On 8 déc, 17:14, Mark Fredrickson <[EMAIL PROTECTED]>
wrote:
> >> Alternatively, could I provide a "multi-
> >> math" lib to redefine the core math functions?
>
> > Type classes would be king.
>
> Do you mean this in the Haskell sense?
Yes :  http://www.haskell.org/tutorial/classes.html
Haskell make a dispatch on type at runtime.

> > (ns test.test
> >  (:refer-clojure :exclude [+ -]))
>
> > (defn +
> >  [a b]
> >  33)
>
> > (+ 1 2) ;= 33
>
> Thanks for the suggestion,

You can "overload" core function :
(binding [clojure.core/compare (constantly 1)]
 (sort [1 5 2 6])) ;(6 2 5 1)

But it wouldn't work  if the function is inline.
(binding [clojure.core/= (constantly false)]
  [(= 1)
   (= 1 1)
   (not= 1 1)
  ])  ; [false true false]

> this will give me a chance to play around  
> with multi-method and see what I think.

I'm not sure, but :
defmethod macro simply call addMethod on clojure.lang.MultiFn object.
So you can add method from an other namespace.

Basically, you would build something like type class.
But it wouldn't play nice with core operator.

pierre
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to