Examples of Haskell Type Errors

How beginners are the beginners you are writing the article for?

Do you consider “Ambiguous type variable” valid errors? In my experience they bite me a lot when I am using a parser combinator library.


Something straight out of the repl:

λ> foldr (+) 0 1

<interactive>:9:1: error: [GHC-39999]
    • Could not deduce ‘Foldable t0’
      from the context: (Foldable t, Num b, Num (t b))
        bound by the inferred type for ‘it’:
                   forall {t :: * -> *} {b}. (Foldable t, Num b, Num (t b)) => b
        at <interactive>:9:1-13
      The type variable ‘t0’ is ambiguous
      Potentially matching instances:
        instance Foldable (Either a) -- Defined in ‘Data.Foldable’
        instance Foldable Maybe -- Defined in ‘Data.Foldable’
        ...plus three others
        ...plus 26 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In the ambiguity check for the inferred type for ‘it’
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      When checking the inferred type
        it :: forall {t :: * -> *} {b}. (Foldable t, Num b, Num (t b)) => b

which is a lot of output for “you forgot square brackets”.

5 Likes