The tutorial lists the following reserved keywords:
if
, then
, else
, when
, as
, is
, dbg
, import
, expect
, expect-fx
, crash
, module
, app
, package
, platform
, hosted
, exposes
, with
, generates
, packages
, requires
Are these up to date? I opened a Roc REPL, and I was able to write x = 123
for x in:
module
, app
, package
, platform
, hosted
, exposes
, with
, generates
, packages
, requires
If these are still reserved keywords, shouldn't the compiler complain if you use them this way?
I think we restricted some of them to specific scopes. So they aren't truly reserved anymore.
Probably should update that
Are you saying we should update the tutorial, or the compiler?
How about exposing
?
There are different reserved keywords when parsing the module header verse the rest of the file I think
crates/compiler/parse/src/keyword.rs
// These keywords are valid in expressions
pub const IF: &str = "if";
pub const THEN: &str = "then";
pub const ELSE: &str = "else";
pub const WHEN: &str = "when";
pub const AS: &str = "as";
pub const IS: &str = "is";
pub const DBG: &str = "dbg";
pub const IMPORT: &str = "import";
pub const EXPECT: &str = "expect";
pub const EXPECT_FX: &str = "expect-fx";
pub const CRASH: &str = "crash";
// These keywords are valid in imports
pub const EXPOSING: &str = "exposing";
// These keywords are valid in types
pub const IMPLEMENTS: &str = "implements";
pub const WHERE: &str = "where";
// These keywords are valid in headers
pub const PLATFORM: &str = "platform";
pub const KEYWORDS: [&str; 11] = [
IF, THEN, ELSE, WHEN, AS, IS, DBG, IMPORT, EXPECT, EXPECT_FX, CRASH,
];
Interesting, thanks @Luke Boswell .
So what would you like me to do?
exposing
, implements
, and where
)?keyword.rs
(module
, app
, package
, hosted
, exposes
, with
, generates
, packages
, and requires
)?I think we would like to have a language reference at some point, and this probably shouldn't live in the tutorial.
I'm not sure we need to start on a language reference right now, so I think it's reasonable to update the tutorial section so it is at least up to date.
Point three is too much detail I think for now.
Here's one proposal, with keywords listed in alphabetical order, for convenience:
These are reserved keywords in Roc. You can't choose any of them as names, except as record field names.
as
, crash
, dbg
, else
, expect
, expect-fx
, if
, import
, is
, then
, when
Other keywords are used in unambiguous contexts, so they are not reserved. This includes:
app
, exposes
, exposing
, generates
, implements
, module
, package
, packages
, platform
, requires
, where
, with
We can drop the second part if you prefer, but it's quite short and some people might be happy to know that they can use names like app
, module
, package
, packages
, platform
, or where
if it's legal and safe.
That sounds good. Thank you
My pleasure. Please see PR #6953.
Last updated: Jul 06 2025 at 12:14 UTC