Can Class do this?

Marcin 'Qrczak' Kowalczyk mk167280@students.mimuw.edu.pl
Tue, 6 Mar 2001 14:05:23 +0100 (CET)


On Tue, 6 Mar 2001, Saswat Anand wrote:

> I guess this can be done using classes, but I have not been successful
> after trying many variations.

It requires extensions supported by ghc and Hugs: multiparameter type
classes are required, functional dependencies are recommended.

Functional dependencies don't work well for released ghc versions, but
shoud work in the upcoming ghc-5.0. You might need to remove '| a b -> c'
below and need more explicit type annotations (will not be very
convenient).

class Plus a b c | a b -> c where
    (\+) :: a -> b -> c

instance Plus CF CF CF where
    f \+ g = ...

instance Plus IF IF IF where
    f \+ g = ...

instance Plus CF IF CIF where
    f \+ g = ...

instance Plus IF CF CIF where
    f \+ g = ...

instance Plus CF CIF CIF where
    f \+ g = ...

instance Plus IF CIF CIF where
    f \+ g = ...

instance Plus CIF CF CIF where
    f \+ g = ...

instance Plus CIF IF CIF where
    f \+ g = ...

instance Plus CIF CIF CIF where
    f \+ g = ...

-- 
Marcin 'Qrczak' Kowalczyk