[Haskell-cafe] Are associated types synonyms like type classes?
Manuel M T Chakravarty
chak at cse.unsw.edu.au
Fri Nov 17 21:23:36 EST 2006
> When using AT then we have to decide what part of the abstraction is
> the class and what part is the associated type. Sometimes this seams
> arbitrary. If we have:
> class A a where
> type B b
> f :: a -> B b
> instance A Int where
> type B = Bool
> f = (==0)
> Can't we also rewrite it as:
> class B b where
> type A a
> f :: A a -> b
> instance B Bool where
> type A = Int
> f = (==0)
If it is arbitrary, you should use a two parameter class. The bias in
an associated type is on purpose; ie, an associated type should be used
if one type depends on the other.
> > Also, has anybody written a paper on the differences between
> > typeclasses + associated types and ML's module system +
> "ML Modules and Haskell Type Classes: A Constructive Comparison"
In addition to this comparison, there is now also a proposal for type
classes with associated types as a mode of use of ML modules. See our
forthcoming POPL paper:
Ie, this gives you ML modules + overloading.
More information about the Haskell-Cafe