Can someone explain why haskell uses an explicit type signature in the following example and how to modify it to avoid the need for an explicit declaration?
import qualified Data.List as L main = do print $ length $ L.nub [1,1,2,3]
Surprisingly, the same code, written interactively in ghci, has no ambiguity problem and makes zero-length printing:
Îģ> :m +Data.List Îģ> print $ length $ nub [] 0 -- ?? can you explain ??
Update: It seems that even the same restriction as the length function of Data.List.nub does not stop complaining about the ambiguous type:
length' :: Eq a => [a] -> Int length' [] = 0 length' (x:xs) = 1 + length' xs main = do print $ length' $ nub [] -- No instance for (Eq a0) arising from a use of 'length'' -- The type variable 'a0' is ambiguous
source share