Back to Examples

Roc

Discover Roc, your go-to platform for seamless application development with powerful tools and intuitive pattern matching. Unlock your coding potential today!

Lines
2,374
Sections
15

Want your own llms.txt file?

Generate a professional, AI-friendly file for your website in minutes!

llms.txt Preview

<input id="tutorial-toc-toggle" name="tutorial-toc-toggle" type= "checkbox">
<nav id="tutorial-toc" aria-label="Table of Contents">
    <label id="close-tutorial-toc" for="tutorial-toc-toggle">close</label>
    <!-- TODO fix search: input [id "toc-search", type "text", placeholder "Search"] [] -->
    <ol>
    <li><a href="#repl">REPL</a></li>
    <li><a href="#building-an-application">Building an Application</a></li>
    <li><a href="#pattern-matching">Pattern Matching</a></li>
    <li><a href="#types">Types</a></li>
    <li><a href="#crashing">Crashing</a></li>
    <li><a href="#testing">Testing</a></li>
    <li><a href="#modules">Modules</a></li>
    <li><a href="#advanced-concepts">Advanced Concepts</a></li>
    </ol>
</nav>
<section id="tutorial-body">
    <section>
        <h1>Tutorial<label id="tutorial-toc-toggle-label" for="tutorial-toc-toggle">contents</label></h1>
        <p>Welcome to Roc!</p>
        <p>This tutorial will teach you how to build Roc applications. Along the way, you'll learn how to write tests, use the REPL, and more!</p>
    </section>
    <section>
        <h2 id="installation"><a href="#installation">Installation</a></h2>
        <p>Roc doesn’t have a numbered release or an installer yet, but you can follow the install instructions for your OS<a href="/install/getting_started.html#installation"> here </a>. If you get stuck, friendly people will be happy to help if you open a topic in<a href="https://roc.zulipchat.com/#narrow/stream/231634-beginners"> #beginners </a>on<a href="https://roc.zulipchat.com/"> Roc Zulip Chat </a>and ask for assistance!</p>
    </section>

## [AI Docs](#ai-docs) {#ai-docs}

We have experimental AI-friendly text files for our [tutorial](/llms.txt) and [standard library](/builtins/llms.txt) that you can use to prompt your favorite large language model to answer your questions about Roc!

## [REPL](#repl) {#repl}

Let's start by getting acquainted with Roc's [_Read-Eval-Print-Loop_](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop), or **REPL** for short.

You can use the online REPL at [roc-lang.org/repl](https://www.roc-lang.org/repl).

Or you can run this in a terminal: <code class="block">roc repl</code>, and if Roc is [installed](/install), you should see this:

<pre>
<samp>
  The rockin’ roc repl
────────────────────────

Enter an expression, or :help, or :q to quit.

</samp></pre>

So far, so good!

### [Hello, World!](#hello-world) {#hello-world}

Try typing this in the REPL and pressing Enter:

<pre><samp class="repl-prompt">"Hello, World!"</samp></pre>

The REPL should cheerfully display the following:

<pre><samp><span class="literal">"Hello, World!" </span><span class="colon">:</span> Str</samp></pre>

Congratulations! You've just written your first Roc code.

### [Naming Things](#naming-things) {#naming-things}

When you entered the _expression_ `"Hello, World!"`, the REPL printed it back out. It also printed `: Str`, because `Str` is that expression's type. We'll talk about types later; for now, let's ignore the `:` and whatever comes after it whenever we see them.

You can assign specific names to expressions. Try entering these lines:

```
greeting = "Hi"
audience = "World"
```

From now until you exit the REPL, you can refer to either `greeting` or `audience` by those names! We'll use these later on in the tutorial.

### [Arithmetic](#arithmetic) {#arithmetic}

Now let's try using an _operator_, specifically the `+` operator. Enter this:

<pre><samp class="repl-prompt">1 <span class="op">+</span> 1</samp></pre>

You should see this output:

<pre><samp>2 <span class="colon">:</span> Num * <span class="comment"></span></samp></pre>

According to the REPL, one plus one equals two. Sounds right!

Roc will respect [order of operations](https://en.wikipedia.org/wiki/Order_of_operations) when using multiple arithmetic operators like `+` and `-`, but you can use parentheses to specify exactly how they should be grouped.

<pre><samp><span class="repl-prompt">1 <span class="op">+</span> 2 <span class="op">*</span> (3 <span class="op">-</span> 4)

-1 <span class="colon">:</span> Num *
</span></samp></pre>

### [Calling Functions](#calling-functions) {#calling-functions}

Let's try calling a function:

<pre><samp><span class="repl-prompt">Str.concat("Hi ", "there.")</span>

<span class="literal">"Hi there."</span> <span class="colon">:</span> Str
Preview of Roc's llms.txt file. View complete file (2,374 lines) →

Ready to create yours?

Generate a professional llms.txt file for your website in minutes with our AI-powered tool.

Generate Your llms.txt File