[Haskell-cafe] type class constraints headache

Rahul Kapoor rk at trie.org
Thu Mar 4 01:15:24 EST 2010


> methods :: (Eq a) => [(String, a)]
> methods =
>   [ ("method1", undefined )
>   , ("method2", undefined)
>   ]
>
> enumerateMethodNames :: [String]
> enumerateMethodNames = map fst methods

The above does not compile because the source does not have
enough information for GHC to determine what actual types to use
for "methods" since undefined can stand in as values for any
type. The program will compile if you use actual values instead
of undefined or supply an explicit type signature.

for example:

enumerateMethodNames = map fst (methods :: [(String, String)])
or
methods :: [(String, SomeEqType)]


Rahul


More information about the Haskell-Cafe mailing list