[Haskell-cafe] Are associated types synonyms like type classes?
Stefan Holdermans
stefan at cs.uu.nl
Fri Sep 1 14:11:58 EDT 2006
Brian,
> 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)
It is more like -- using multi-parameter type classed with functional
dependencies (as found, for example, in GHC):
class A a b | a -> b where
foo :: a -> b
instance A Int Bool where
foo = (== 0)
Cheers,
Stefan
More information about the Haskell-Cafe
mailing list