BT

InfoQ Homepage News New Elm Release Helps Developers Learn Syntax

New Elm Release Helps Developers Learn Syntax

Bookmarks

Evan Czaplicki, Elm’s creator, recently released Elm 0.19.1 with improved error messages. Elm 0.19.1 goes a step further in realizing Elm’s vision of being a delightful language for reliable webapps. The new release comes a year after the previous one (0.19) which emphasized smaller assets, and faster builds.

In the release blog post, Czaplicki explained his desire to “get the compiler to a point where people feel like it is actually helping them learn Elm syntax”. Czaplicki gives the hypothetical example of a JavaScript developers reusing the JavaScript syntax for imports in Elm:

import * as Set from 'set'

The error message displayed by Elm will be:

- EXPECTING IMPORT NAME ------------------------------------------ src/Main.elm

I was parsing an `import` until I got stuck here:

1| import * as Set from 'set'
          ^
I was expecting to see a module name next, like in these examples:

    import Dict
    import Maybe
    import Html.Attributes as A
    import Json.Decode exposing (..)

Notice that the module names all start with capital letters. That is required!

Read <https://elm-lang.org/0.19.1/imports> to learn more.

Errors related to curly braces are also given specific attention. For instance, the following Elm code misses a closing curly brace:

type alias Student =
    { firstName : String
    , lastName : String
    , completedAssignmentIds : Set Int

The resulting error message suggests a viable fix:

-- UNFINISHED RECORD TYPE ----------------------------------------- src/Main.elm

I was partway through parsing a record type, but I got stuck here:

4|     { firstName : String
5|     , lastName : String
6|     , completedAssignmentIds : Set Int
                                         ^
I was expecting to see a closing curly brace next. Try putting a } next and see
if that helps?

Note: I may be confused by indentation. For example, if you are trying to define
a record type across multiple lines, I recommend using this format:

    { name : String
    , age : Int
    , height : Float
    }

Notice that each line starts with some indentation. Usually two or four spaces.
This is the stylistic convention in the Elm ecosystem.

Previously, the 0.15.1 release focused on compiler errors, in particular locating the faulty code, content and formatting of the error message, together with hints to fix the error. The subsequent 0.16 release improved error messages further by leveraging the community feedback on Elm’s error message catalog. Concretely, the 0.16 release added better type diffs, provided more context around type errors and eliminated cascading errors.

Developers interested in exploring the new syntax error messages with Elm 0.19.1 may experiment with examples in Elm’s online editor or start working through the The Official Guide. The release note contains additional information on the new error messages brought about by the 0.19.1 release.

Czaplicki encourages Elm developers to share further any confusing error messages they encounter while learning Elm in elm/error-message-catalog.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.