BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

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

BT