For complex cases, you may like to fall back on multi-methods and
abstraction types. I blogged about typed abstractions few days ago
here:

http://bitumenframework.blogspot.com/2010/10/typed-abstractions-in-clojure.html

Regards,
Shantanu

On Nov 4, 1:25 pm, "nicolas.o...@gmail.com" <nicolas.o...@gmail.com>
wrote:
> I see your point.
> Somehow, it is annoying to have to manipulate a set of protocols that
> always go together.
> And it would be nice to have a shorthand.
>
> I have a very small prototype here:
>
> git://nicolasoury.repositoryhosting.com/nicolasoury/type-classes.git
>
> of some code to allow "type-classes" like deductions of protocols (ie
> logical programming with protocols).
>
> It is not really working, tested, maintained or nice currently.
> (It was just a quick proof of concept)
>
> The idea is to write a rule:
>
> Serializable, Comparable, HalfCool => Cool  {implemenation of
> functions that are not in the pre-condition}
>
> Typically if you roll you own Eq protocol with eq,
>
> Comparable => Eq {:eq (fn [x y] (compare x y)}
>
> Then, for each protocol accessible on a right handside of a rule, it
> extends Object with that protocol.
>
> This default implementation try to apply all rules, in order to deduce
> an implementation.
> If it deduces an implementation, it extends the protocol with that
> implementation, for the type of the argument.
> (That way there is a derivation of implementation only on the first call)
>
> The implementation is very bad (and not maintained) and I wouldn't
> advise using it, but the idea can be useful sometimes.
>
> Especially, it shows that the access you have to protocols at the
> programmatic level, might help to solve the kind of problems you have.
> (this kind of deduction are a bit of an overkill for the problem at hand)
>
> I don't know if there is a similar programmatic  access to deftype. I
> would like to know of it if there is.
>
> 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

Reply via email to