On 1 July 2012 16:39, David Nolen <dnolen.li...@gmail.com> wrote: > On Sun, Jul 1, 2012 at 10:31 AM, Michał Marczyk > <michal.marc...@gmail.com> wrote: >> Additionally I would like to note that Haskell's ad hoc polymorphism >> solution, the system of type classes, allows for extensions predicated >> on a type class already being implemented: >> >> -- no dependencies on other type classes >> instance SomeClass SomeType where >> ... >> >> -- depend on OtherClass being implemented >> instance (OtherClass a) => SomeClass a where >> ... > > This is pretty interesting. This could address the issues around > knowing exactly which protocols you need to implement in order to get > map-like functionality for example. > > (defprotocol ILast :where [IIndexed] > ...) > > So this expresses dependency w/o inheritance.
Actually the type class definition itself includes no information about dependencies; for example, here's the analogue of IEquiv: class Eq a where (==) :: a -> a -> Bool (/=) :: a -> a -> Bool It's possible to provide default implementations of some methods in terms of the others (and indeed Eq does provide a default impl for (==) in terms of (/=) and a default impl for (/=) in terms of (==); it is up to you whether to override one of them (either one) or both). Then when making a type an instance of a particular type class you can specify some extra context (the part before =>): instance (Eq a) => Eq [a] where ... This says that lists of items which may be compared for equality can themselves be compared for equality. Because of the context, you can use (==) / (/=) on the a items when defining (==) / (/=) on [a]. There is indeed no inheritance. Well, admittedly, extending a protocol to an interface involves no inheritance either. Of course with type classes, there is just the one notion and everything is open. A lovely system overall. Cheers, M. > > David > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en