Holmusk/elm-street

Adding documentation for reserved words in elm

JolandaNava opened this issue · 1 comments

Some words in elm are considered reserved and naming a record field with one of these words will result in the generated elm files to not compile.

For example the Haskell new type

data NewData = NewData
    { ndType :: Text
    } deriving stock (Show, Eq, Generic)
      deriving (FromJSON, ToJSON, Elm) via ElmStreet Project

will produce the following in the Elm Types file:

type alias NewData =
    { type : String
    }

which will not compile due to the word type being used as a record field name.

The following is a list of reserved words according to the code in the elm compiler:
"if", "then", "else", "case", "of", "let", "in", "type", "module", "where", "import", "exposing", "as", "port"

It might be good to include them in the documentation with a warning to not name fields in Haskell that would reduce to reserved words once stripped of their prefix. Especially since the errors produced by Elm in these instances are not the most helpful:

Something went wrong while parsing a record type.

39|     { type : String
          ^
I was expecting to see a lower-case variable, like `x` or `user`

Another restriction now is tag field as it's reserved for constructor name due to options of aeson library.