Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding documentation for reserved words in elm #73

Closed
JolandaNava opened this issue Aug 15, 2019 · 1 comment · Fixed by #82
Closed

Adding documentation for reserved words in elm #73

JolandaNava opened this issue Aug 15, 2019 · 1 comment · Fixed by #82
Assignees
Labels

Comments

@JolandaNava
Copy link
Member

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`
@vrom911 vrom911 self-assigned this Sep 3, 2019
@vrom911
Copy link
Contributor

vrom911 commented Sep 3, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants