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:
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With