[Haskell-cafe] type class constraints headache

Marcus Uneson marcus.uneson at gmail.com
Thu Mar 4 01:48:01 EST 2010


Thanks. I realize there are many ways to make it compile.
However, I am trying to understand the mechanism behind --
why does the first example compile and what constraints does
enumerateMethodNames add on a (which it does not inspect)?


cheers,

Marcus

2010/3/4 Rahul Kapoor <rk at trie.org>

> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100304/eb87dad8/attachment.html


More information about the Haskell-Cafe mailing list