Bulat, Stefan,<br><br>My question wasn't clear. I understand already that classes with associated types are are alternative to MPTC with fundeps.<br><br>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:
<br><br> class A a where<br> type B b<br> f :: a -> B b<br> instance A Int where<br> type B = Bool<br> f = (==0)<br><br>Can't we also rewrite it as:<br> <br> class B b where<br>
type A a<br> f :: A a -> b<br> instance B Bool where<br> type A = Int<br> f = (==0)<br><br>What is the practical difference between class A and class B? With class A we can define instances so that f is overloaded (Int -> Bool), (String -> Bool), (Bool -> Bool) by defining instances of A for Int, String, and Bool, but we cannot overload it more (Int -> String), (Int -> Int) because we can only have on "instance A Int". The converse is true for class B. Is that the only difference?
<br><br>If so, then why do we have "associated types" instance of "associated classes" like this?:<br> <br> class A a where<br> class B b where<br> f :: a -> b<br><br> instance A Int where
<br> instance B Bool where<br> f = (==0)<br><br>The made-up syntax I presented in my previous message was just a different way of writing the above (which is also made-up syntax):<br><br> class A a, B b where f :: a -> b
<br> instance A Int, B Bool where f = (==0)<br><br> class Elem elem, Collect collect where<br> empty :: collect<br> insert :: elem -> collect -> collect<br> toList :: collect -> [elem]<br>
<br>Thanks for your help,<br>Brian<br><br><br><div><span class="gmail_quote">On 9/1/06, <b class="gmail_sendername">Bulat Ziganshin</b> <<a href="mailto:bulat.ziganshin@gmail.com">bulat.ziganshin@gmail.com</a>> wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello Brian,<br><br>Friday, September 1, 2006, 8:32:55 PM, you wrote:<br><br>> I read the easy parts of the "Associated Types with Class" and
<br>> "Associated Type Synonyms" papers. An associated type synonym seems<br>> to kind of work similarly to a restricted form of class. In what way<br>> are the two following examples different?<br><br>
> -- define a class with a type synonym, and a set of operations<br>> class A a where<br>> type B b<br>> foo :: a -> B b<br><br>> instance A Int where<br>> type B = Bool<br>> foo = (==0)<br><br>> -- define two classes, and an function that .
<br>> class A a, B b where<br>> foo :: a -> b<br><br>> instance A Int, B Bool where<br>> foo = (==0)<br><br>where you've find such unusual syntax? :) GHC/Hugs supports<br>multi-parameter type classes (MPTC):
<br><br>class AB a b where<br> foo :: a -> b<br><br>instance AB Int Bool where<br> foo = (==0)<br><br>AT replaces MPTC with FD (functional dependency), which allows to<br>specify which type parameter of MPTC is detremined by another one,
i.e.:<br><br>class AB a b | a->b where ....<br><br>for further details about MPTC+FD see chapter 7.1.1 in the<br><a href="http://cvs.haskell.org/Hugs/pages/hugsman/exts.html">http://cvs.haskell.org/Hugs/pages/hugsman/exts.html
</a><br><br><br><br>> Also, has anybody written a paper on the differences between<br>> typeclasses + associated types and ML's module system + overloading?<br><br>"ML Modules and Haskell Type Classes: A Constructive Comparison"
<br><a href="http://www.informatik.uni-freiburg.de/~wehr/diplom/Wehr_ML_modules_and_Haskell_type_classes.pdf">http://www.informatik.uni-freiburg.de/~wehr/diplom/Wehr_ML_modules_and_Haskell_type_classes.pdf</a><br><br><br>
--<br>Best regards,<br> Bulat mailto:<a href="mailto:Bulat.Ziganshin@gmail.com">Bulat.Ziganshin@gmail.com</a><br><br></blockquote></div><br>