Stream: beginners

Topic: as keyword not recognized by compiler


view this post on Zulip Ian McLerran (Aug 26 2022 at 00:39):

I am walking through the Roc tutorial, and got to the introduction of the as keyword. However I get the following compiler error when I run:

── MISSING ARROW ─────────────────────────────────────────────────── Hello.roc 
I am partway through parsing a function argument list, but I got stuck
here:
10  addAndStringify = \{ iguanas: lizards } as counts ->
                                              ^
I was expecting a -> next.

My code is verbatim what is shown in the tutorial (Lines 383-384):

addAndStringify = \{ iguanas: lizards } as counts ->
    Num.toStr (counts.birds + lizards)

Any ideas what might be going on here?

NOTE: I am on commit 35de4c6 - latest from main at time of writing

view this post on Zulip Brendan Hansknecht (Aug 26 2022 at 02:10):

Looking across current Roc code and poking around a bit, I think that as is currently only available in a limited scope.

It seems that it works in type definitions where it is used for some platform related type naming, but I don't see any variable naming use cases.

view this post on Zulip Brendan Hansknecht (Aug 26 2022 at 02:10):

Would you mind filing a bug for this?

view this post on Zulip Brendan Hansknecht (Aug 26 2022 at 02:11):

Then someone with more context on this feature can take a proper look.

view this post on Zulip Brendan Hansknecht (Aug 26 2022 at 02:12):

I guess for now, we are stuck with destructuring:

addAndStringify = \counts ->
    { iguanas: lizards } = counts
    Num.toStr (counts.birds + lizards)

view this post on Zulip Ian McLerran (Aug 26 2022 at 17:33):

Brendan Hansknecht Thanks so much for the response! I can definitely file an issue for this. On a side note, I'm still working on comprehending the codebase. Would you mind pointing me toward which files you were looking at to find the behavior of the as keyword?

view this post on Zulip Ian McLerran (Aug 26 2022 at 17:57):

Okay, per your recommendation, I've opened an issue for this here

view this post on Zulip Brendan Hansknecht (Aug 26 2022 at 18:20):

In this case, I didn't feel like actually digging into the parser or anything complex. Instead I:

  1. Ran a number of examples manually through the compiler to see if anything worked.
  2. Looked for all uses of as in .roc files.

Last updated: Jul 26 2025 at 12:14 UTC