Haskell' - class aliases

Claus Reinke claus.reinke at talk21.com
Fri May 2 09:06:24 EDT 2008


>    A aliasing of constraints/classes
>        (this is the semantic part that could also be explained by
>        reduction, or by simple mutual implication encodings)
> 
>    B aliasing of syntax, especially instance definitions
>        (this syntactic part is hard to encode, and simple in
>        terms of syntactic macro expansion)

it just occurred to me that there is a precedence for this kind
of translation, in associated types and type functions.

defining an AT in a class is equivalent to defining a TF
outside the class, and connecting the TF to the class with
superclass and instance constraints, right?

    class C a where
        type CT a
        c :: (a,CT a)

    instance C a where
        type CT a = ..
        c = ..

    -- vs

    type family CT a
    type instance CT a = ..

    class CT a ~ b => C a where c :: (a,CT a)
    instance CT a ~ b => C a where c = ..

though the latter form is not yet supported in GHC (#714).

which leads me to a problem i have with ATs, which applies
to class aliases as well: although the ATs are written as if they
were local to the class, they get lifted out of the class in a naive
manner. in particular, they can only refer to their parameters, 
not to other local definitions/types, and their parameters have 
to match the class parameters.

however, i assume that the restrictions/translations/implementations
for class aliases are similar to the those for the implementation 
of ATs in terms of TFs, which might help?

claus





More information about the Haskell-prime mailing list