Providing a :default implementation for multimethods is a very common  
and useful technique, but it is really useful only for multimethods  
that dispatch on a single argument. What I am looking for is an  
equivalent technique for multiple-argument dispatch.

Suppose you have a multimethod + of two arguments, and you want to  
dispatch on both of them:

        (defmulti + (fn [x y] [(type x) (type y)]))

You can then write implementations such as

        (defmethod + [java.lang.Integer java.lang.Double] ...)

You can also provide a default implementation, of course:

        (defmethod + :default  ...)

But suppose you want to provide a default for one argument only?  
Something like

        (defmethod + [java.lang.Integer ::any] ...)

i.e. a multimethod that matches all invocations in which the first  
argument is an integer. I don't currently see a simple way to do  
this. For types in the Java class hierarchy, you can use Object as  
the parent of all types, but there is nothing equivalent in Clojure's  
ad-hoc hierarchies.

Would it be a good idea to provide the possiblity to add a universal  
parent to hierarchies? Or would that create any problems? Is there  
another solution for the situation I described?

Konrad.


--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to