On Dec 1, 2007, at 21:43 , PR Stanley wrote:

Hi
> type assoc k v = [(k, v)]

works beautifully and everything makes sense.

> type Assoc v = (Ord k) => [(k, v)]

This doesn't work. Is there any wayof defining k as an element of type Ordinal. I could redefine k by putting Char or Int in its place. Why can't I be more general?

Think of a type declaration as a macro which is expanded where it is used. With parentheses around it and any unresolved references "forall"ed, because it has no idea what to do with them at declaration time.

So, if you use -fglasgow-exts, you could make the above type declaration. But when you use it:

  foo :: Assoc Int -> Assoc Int

translates as

foo :: (forall k. (Ord k) => [(k,Int)]) -> (forall k. (Ord k) => [(k,Int)])

This is almost certainly *not* what you want; the two "k"s are independent.

It could be argued that GHC should be smarter about it... but formalizing what that means is difficult (and subject to disagreements).

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to