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
foralled, 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 ks 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 universityKF8NH
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe