Haskell's dreaded monomorphism restriction.
Haskell's monomorphism restriction causes some functions that should be polymorphic to be forced into monomorphism, causing errors. For instance:
sum = foldr (+) 0
in GHC 7.10, this will fail with this message:
No instance for (Foldable t0) arising from a use of ‘foldr’
The type variable ‘t0’ is ambiguous
Relevant bindings include
mysum :: t0 Integer -> Integer (bound at src/Main.hs:37:1)
Note: there are several potential instances:
instance Foldable (Either a) -- Defined in ‘Data.Foldable’
instance Foldable Data.Functor.Identity.Identity -- Defined in ‘Data.Functor.Identity’
instance Foldable Data.Proxy.Proxy -- Defined in ‘Data.Foldable’
...plus five others
In the expression: foldr (+) 0
In an equation for ‘mysum’: mysum = foldr (+) 0
This can usually be solved by explicitly defining the type signature:
sum :: (Foldable f, Num a) => f a -> a
Or by removing the restriction:
{-# LANGUAGE NoMonomorphismRestriction #-}