Dhall-haskell: Unclear parsing error when using an alias as type annotation on empty List

Created on 29 May 2018  ·  8Comments  ·  Source: dhall-lang/dhall-haskell

Afaik empty lists require a type annotation, but it seems to break on aliased types.

Example:

   let genericRecord = List { mapKey : Text, mapValue : Text }
in ([] : genericRecord)

Evaluating this returns:

Error: Invalid input

(stdin):2:6: error: expected: expression,
    whitespace
in ([] : genericRecord)
     ^

While writing down the type inplace works.
(that is: ([] : List { mapKey : Text, mapValue : Text }))

Dhall version: 1.11.1

error messages

Most helpful comment

I don't think the FAQ is sufficient to close this. It's a really understandable mistake to make, and getting a parse error about whitespace is not at all enlightening. You can only resolve the error if you know the grammar. I think the error message needs to be improved and this should be re-opened.

All 8 comments

You have to do this:

   let genericRecord = { mapKey : Text, mapValue : Text }
in ([] : List genericRecord)

I believe.

Yep, what @ocharles said :)

The trick is to realize that the type annotation for empty lists is not a real type annotation. It's actually part of the grammar:

Syntax
↓↓↓↓↓↓↓↓↓
[] : List ElementType

I can add this gotcha to the FAQ if that helps

Isn't the error message a bit confusing in this case ? For a while I could not figure out the relation between the title of the issue and the issue itself ;-)
👍 to add this in the FAQ

Oh cool, thanks for the clarification.
Makes sense, but I agree on putting this in the FAQ, as it's not conformant to what one might expect.

Added to the FAQ, closing.

I don't think the FAQ is sufficient to close this. It's a really understandable mistake to make, and getting a parse error about whitespace is not at all enlightening. You can only resolve the error if you know the grammar. I think the error message needs to be improved and this should be re-opened.

I think the error message needs to be improved and this should be re-opened.

Agreed 👍
Renamed the issue accordingly.

@ocharles @f-f: Note that improving the error message requires a change to the language standard since : List is part of the grammar for empty list literals, so this issue might be more appropriate for the dhall-lang repository

Was this page helpful?
0 / 5 - 0 ratings