[Haskell-cafe] Are associated types synonyms like type classes?

Bulat Ziganshin bulat.ziganshin at gmail.com
Fri Sep 1 13:26:21 EDT 2006


Hello Brian,

Friday, September 1, 2006, 8:32:55 PM, you wrote:

> I read the easy parts of the "Associated Types with Class" and
> "Associated Type Synonyms" papers. An associated type synonym seems
> to kind of work similarly to a restricted form of class. In what way
> are the two following examples different? 

>     -- define a class with a type synonym, and a set of operations
>     class A a where
>         type B b
>         foo :: a -> B b

>     instance A Int where
>         type B = Bool
>         foo = (==0) 

>     -- define two classes, and an function that .
>     class A a, B b where
>         foo :: a -> b

>      instance A Int, B Bool where
>           foo = (==0)

where you've find such unusual syntax? :)  GHC/Hugs supports
multi-parameter type classes (MPTC):

class AB a b where
    foo :: a -> b

instance AB Int Bool where
    foo = (==0)

AT replaces MPTC with FD (functional dependency), which allows to
specify which type parameter of MPTC is detremined by another one, i.e.:

class AB a b | a->b where ....

for further details about MPTC+FD see chapter 7.1.1 in the
http://cvs.haskell.org/Hugs/pages/hugsman/exts.html
 


> Also, has anybody written a paper on the differences between
> typeclasses + associated types and ML's module system + overloading? 

"ML Modules and Haskell Type Classes: A Constructive Comparison"
http://www.informatik.uni-freiburg.de/~wehr/diplom/Wehr_ML_modules_and_Haskell_type_classes.pdf


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list