Yes, Haskell type classes are the sort of thing I have in mind here I think. On a type class you can specify default implementations of any or all of the functions, and they can even refer to themselves cyclically (e.g the Eq class where == and /= are defined as each other's complements): the instance just needs to provide whichever one is most suitable.
Matthew. On Aug 14, 9:30 pm, Nicolas Oury <nicolas.o...@gmail.com> wrote: > On Sat, Aug 14, 2010 at 5:32 AM, Matthew Phillips <mattp...@gmail.com> wrote: > > > One idea that I tried was to use extend-type on a protocol, say to > > extend any Node to be a PrettyPrintableNode. Obviously this didn't > > work, and I'm not sure it actually makes semantic sense, but it's > > interesting that was my intuitive action. > > I played with that kind of things a bit and come up with a - very > alpha - library some time ago. > > I called it type classes because it does a part of what Haskell's type > classes do. > > You can define a rule: > > Node => PrettyPrintableNode (implementation of PrettyPrintableNode using Node) > > And it extends Object with a default implementatiuon of protocol > PrettyPrintable, that just takes the object it is called on, > looks at its type, and try to apply the rules it can apply to it (You > could have a rule NodeV2-25 => PrettyFormatable and another > PrettyFormatable, ... => PrettyPrintable). > If it finds a non-cyclic path to construct a PrettyPrintable instance, > it extend the types with the right protocols implementation, and > recalls the function. > > I planned to improve on it, but it seems there were a really low > interest for this kind of thing on the list when I posted. > > I wouldn't recommand to use it in this state, but if you want to have > a look at the code: > > https://nicolasoury.repositoryhosting.com/trac/nicolasoury_type-classes > > Best, > > Nicolas. -- 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