Examples of Haskell Type Errors

It’s a great initiative, but sadly error codes are ungooglable. For “GHC-39999” (with and without quotes) from this thread, it doesn’t lead me to Haskell Error Index, actually, at all (!!). Yes, I did check every google result, I did learn that GHC is a currency sign for Ghanaian cedi, but no error index in sight. It’s even worse, “Haskell Error Index” (with and without quotes) doesn’t lead me to the page also (this time I did check first 3 result pages).

Something clearly doesn’t work with that website.

7 Likes

Very strange. I reported it here: Doesn't seem to be indexed well by search engines · Issue #537 · haskellfoundation/error-message-index · GitHub

4 Likes

SML/NJ Error and Warning Messages lists (normal) error messages returned by the SML/NJ compiler. From your post, it seems that you want to create something similar but for GHC/Haskell?

1 Like

That sounds similar to the Haskell Error Index. That’s a great resource.

I’m writing something a bit different: some concrete suggestions for how to deal with type errors that point to the wrong place or are hard to understand/fix for some other reason. These are often totally “normal” type errors that are confusing because of how type inference works or because code is a bit too polymorphic or weird.

Errors related to rank-n-types often trip people up, like the one in this Reddit thread.

A tiny example:

foo :: forall x . Show x => Maybe x -> [(String,x)]
foo m = maybeToList $ (\z -> (show z,z)) <$> m

bar :: (forall x . Maybe x -> [(String,x)]) -> Maybe x -> [(String,x)]
bar f m = f m

baz :: [(String,Int)]
baz = bar foo (Just 5)

which results in:

    • No instance for ‘Show x’ arising from a use of ‘foo’
      Possible fix:
        add (Show x) to the context of
          a type expected by the context:
            forall x. Maybe x -> [(String, x)]
    • In the first argument of ‘bar’, namely ‘foo’
      In the expression: bar foo (Just 5)
      In an equation for ‘baz’: baz = bar foo (Just 5)
1 Like

One in the wild:

<interactive>:2:1: error:
    • Couldn't match representation of type ‘a0’
                               with that of ‘haskell-gi-base-0.26.8:Data.GI.Base.BasicTypes.ManagedPtr
                                               ()’
        arising from a superclass required to satisfy ‘Coercible
                                                         a0
                                                         (haskell-gi-base-0.26.8:Data.GI.Base.BasicTypes.ManagedPtr
                                                            ())’,
        arising from a superclass required to satisfy ‘haskell-gi-base-0.26.8:Data.GI.Base.BasicTypes.ManagedPtrNewtype
                                                         a0’,
        arising from a superclass required to satisfy ‘haskell-gi-base-0.26.8:Data.GI.Base.BasicTypes.GObject
                                                         a0’,
        arising from a use of ‘passwordLookupSync’
    • In the expression:
        passwordLookupSync
          Nothing (Map.fromList [("key", "value")]) Nothing
      In an equation for ‘it’:
          it
            = passwordLookupSync
                Nothing (Map.fromList [("key", "value")]) Nothing

It is still being diagnosed, I would have no idea where to start with this.

3 Likes