Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the reserved keywords in Elm?

Tags:

elm

Every once in a while you get a compiler error like this:

It looks like the keyword `port` is being used as a variable.

That's annoying. Is there a complete official list of these keywords? I've gotten as far as finding where the error messages are generated, but I couldn't find where the keywords are actually defined.

Meanwhile, here's a probably incomplete or incorrect list of keywords I found by browsing the syntax page and trying keywords in the repl:

  • let
  • in
  • where
  • module
  • exposing
  • type
  • port
  • import
  • infixr
  • as
  • if
  • else
  • then
like image 470
Andreas Hultgren Avatar asked Oct 15 '16 10:10

Andreas Hultgren


People also ask

Which are reserved keywords?

Reserved words (also called keywords) are defined with predefined meaning and syntax in the language. These keywords have to be used to develop programming instructions. Reserved words can't be used as identifiers for other programming elements like name of variable, function etc.

What do you mean by reserved keywords explain with example?

1. Often found in programming languages and macros, reserved words are terms or phrases appropriated for special use that may not be utilized in the creation of variable names. For example, "print" is a reserved word because it is a function in many languages to show text on the screen. 2.

Why keywords are called reserved words?

In many languages, such as C and similar environments like C++, a keyword is a reserved word which identifies a syntactic form. Words used in control flow constructs, such as if , then , and else are keywords. In these languages, keywords cannot also be used as the names of variables or functions.


1 Answers

According to the elm-compiler source code the list of reserved keywords is:

keywords =
  Set.fromList
    [ "if", "then", "else"
    , "case", "of"
    , "let", "in"
    , "type"
    , "module", "where"
    , "import", "exposing"
    , "as"
    , "port"
    ]

Edit: There are actually some more keywords (found by searching for "reserved" in the repo) I've found: infix, infixl, infixr. infixr has also be noted by the OP.

like image 160
dotcs Avatar answered Oct 05 '22 15:10

dotcs