type error formatting

Edward Z. Yang ezyang at mit.edu
Sat Oct 24 02:50:57 UTC 2015


I think this is quite a reasonable suggestion.

Edward

Excerpts from Evan Laforge's message of 2015-10-23 19:48:07 -0700:
> Here's a typical simple type error from GHC:
> 
> Derive/Call/India/Pakhawaj.hs:142:62:
>     Couldn't match type ‘Text’ with ‘(a1, Syllable)’
>     Expected type: [([(a1, Syllable)], [Sequence Bol])]
>       Actual type: [([Syllable], [Sequence Bol])]
>     Relevant bindings include
>       syllables :: [(a1, Syllable)]
>         (bound at Derive/Call/India/Pakhawaj.hs:141:16)
>       best_match :: [(a1, Syllable)]
>                     -> Maybe (Int, ([(a1, Syllable)], [(a1, Sequence Bol)]))
>         (bound at Derive/Call/India/Pakhawaj.hs:141:5)
>     In the second argument of ‘mapMaybe’, namely ‘all_bols’
>     In the second argument of ‘($)’, namely
>       ‘mapMaybe (match_bols syllables) all_bols’
> 
> I've been having more trouble than usual reading GHC's errors, and I
> finally spent some time to think about it.  The problem is that this new
> "relevant bindings include" section gets in between the expected and actual
> types (I still don't like that wording but I've gotten used to it), which
> is the most critical part, and the location context, which is second most
> critical.  Notice the same effect in the previous sentence :)  After I see
> a type error the next thing I want to see is the where it happened, so I
> have to skip over the bindings, which can be long and complicated.  Then I
> usually know what to do, and only look into the bindings if something more
> complicated is going on, like wonky inference.  So how about reordering the
> message:
> 
> Derive/Call/India/Pakhawaj.hs:142:62:
>     Couldn't match type ‘Text’ with ‘(a1, Syllable)’
>     Expected type: [([(a1, Syllable)], [Sequence Bol])]
>       Actual type: [([Syllable], [Sequence Bol])]
>     In the second argument of ‘mapMaybe’, namely ‘all_bols’
>     In the second argument of ‘($)’, namely
>       ‘mapMaybe (match_bols syllables) all_bols’
>     Relevant bindings include
>       syllables :: [(a1, Syllable)]
>         (bound at Derive/Call/India/Pakhawaj.hs:141:16)
>       best_match :: [(a1, Syllable)]
>                     -> Maybe (Int, ([(a1, Syllable)], [(a1, Sequence Bol)]))
>         (bound at Derive/Call/India/Pakhawaj.hs:141:5)
> 
> After this, why not go one step further and set off the various sections
> visibly to make it easier to scan.  The context section can also be really
> long if it gets an entire do block or record:
> 
> Derive/Call/India/Pakhawaj.hs:142:62:
>   * Couldn't match type ‘Text’ with ‘(a1, Syllable)’
>     Expected type: [([(a1, Syllable)], [Sequence Bol])]
>       Actual type: [([Syllable], [Sequence Bol])]
>   * In the second argument of ‘mapMaybe’, namely ‘all_bols’
>     In the second argument of ‘($)’, namely
>       ‘mapMaybe (match_bols syllables) all_bols’
>   * Relevant bindings include
>       syllables :: [(a1, Syllable)]
>         (bound at Derive/Call/India/Pakhawaj.hs:141:16)
>       best_match :: [(a1, Syllable)]
>                     -> Maybe (Int, ([(a1, Syllable)], [(a1, Sequence Bol)]))
>         (bound at Derive/Call/India/Pakhawaj.hs:141:5)
> 
> Or alternately, taking up a bit more vertical space:
> 
> Derive/Call/India/Pakhawaj.hs:142:62:
>     Couldn't match type ‘Text’ with ‘(a1, Syllable)’
>     Expected type: [([(a1, Syllable)], [Sequence Bol])]
>       Actual type: [([Syllable], [Sequence Bol])]


More information about the Glasgow-haskell-users mailing list