Haskell' - class aliases

John Meacham john at repetae.net
Fri May 2 05:50:20 EDT 2008


This isn't really a response to your email, but I have been mulling the
last few hours away from a computer and wanted to get this stream of
conciousness out when it is fresh in my mind.

The more I think about it, I think 'superclass' is just the wrong
terminology for dealing with class aliases. Superclass implies a strict
partial order on classes, which just isn't the case for class aliases,
for instance

> class alias Foo a => Foo a = Bar a where ...

Has a defined (if not very useful) meaning with class aliases, but is
really odd if you consider 'Foo a' a "superclass". So, I think the
following terminology should be used:

   Context of --+
   alias        |     The alias -+    +--- The expansion of the alias
                |                |    |
                v                v    v
> class alias (S1 a .. Sn a) => A a = (C1 a ... Cn a) where
>      fd1 = ....
>      ....
>      fdn = ....
            ^
            +----  The defaults of the alias



given this, the expansion of 'A a' in any context other than an instance
head is

> A a --> reduce(S1 a .. Sn a, C1 a ... Cn a)

where reduce is standard entailment reduction on class contexts (like (Eq
a,Ord a, Eq a) reduces to (Ord a))

This expansion is carried out iteratively on all class aliases  until a
fixed point is reached, then all class aliases are deleted from the
result and the remaining context is the final result. (This will always
terminate due to there being a finite number of class aliases that can
be pulled into the expansion)


likewise, for instance declarations:


> instance A a where ...

--> 

> foreach C in C1 .. Cn:
>    instance (S1 a ... Sn a) => C a where ...

I left out the default methods here. I need to think about them a bit
more to come up with a formal expansion as it is a bit trickier (to
typeset if nothing else), but I hope this is somewhat more clear for
some...

        John




-- 
John Meacham - ⑆repetae.net⑆john⑈


More information about the Haskell-prime mailing list