Multiparameter classes in HUGS and GHC

Graham Klyne gk@ninebynine.org
Wed, 30 Apr 2003 21:26:06 +0100


At 14:45 30/04/2003 -0400, Dean Herington wrote:
>Again the kinds are wrong.  However, you can't make a Pair instance out of 
>MyPair4 because the latter is
>a `type` rather than `newtype` or `data`.
>
>Hope this helps.

Yes, very much, thank you.

If I now have this right, it's the distinction between a parametric 
polymorphic type and an algebraic type constructor that I had failed to 
properly appreciate.  Now I'm alerted to it, I don't know why I didn't 
realize sooner that something there was wrong.

I discover that I can also use:
[[
type MyPair5 = (,)

instance Pair MyPair5 Int String where
     newPair = id
     getPair = id
]]
though I'm not sure how MyPair5 is interpreted as a type synonym ;-)


There's a small matter that still puzzles me a little.  In:
[[
data (Eq a, Show a) => MyPair3 a b = P3 a b

instance Pair MyPair3 Int String where
     newPair (x,y) = P3 x y
     getPair (P3 x y) = (x,y)
]]
(which seems OK), "Pair3" is a type _expression_ of kind (* -> * -> *), the 
corresponding _constructor_ for which is P3.  Yet, according to [1], "(,)" 
is a type _constructor_.  I guess there may be some terminological 
crossover here as type constructors often use the same name as the 
corresponding type expression?

[1] http://haskell.org/onlinereport/decls.html#sect4.1.2

#g


-------------------
Graham Klyne
<GK@NineByNine.org>
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E