type error formatting

Roman Cheplyaka roma at ro-che.info
Sat Oct 24 10:07:14 UTC 2015


I have the same issue with the current error messages. I think these are
all good ideas.

On 10/24/2015 05:48 AM, Evan Laforge wrote:
> 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])]
>         -----------------------------
>     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)
> 
> Thoughts?  It seems simple enough that I could do myself, but of course
> not without buy-in.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/glasgow-haskell-users/attachments/20151024/07316559/attachment.sig>


More information about the Glasgow-haskell-users mailing list