> AFAIK, it is not possible. You must implement all the different protocols.
> It might look desapointing, but on the other hand it is not necessary.
> (As there is no static typing in Clojure)
> What is your use-case?

Current use case is that I want an abstraction which comprises of a
set of operations I want + Comparable + Serializable

> Just define types that extend all the protocols.
> You can't. But you can define a type that extends both P and Comparable.

Currently I'm struggling with the following problem - Suppose I
consider something satisfying 'Coolness' property if it does x, y, z +
is comparable + serializes.

To do this I create a protocol 'OnlyHalfCoolness':
(defprotocol OnlyHalfCooless x y z)

and two deftypes Cool1, Cool2:
(deftype Cool1 ... OnlyHalfCoolness .. Comparable .. Serializable)
(deftype Cool2 ... OnlyHalfCoolness .. Comparable .. Serializable)

Now I need to write a function: is-this-cool?

Instead of
(defn is-this-cool? [o] (satisfies? Coolness o))

I need to now write:
(defn is-this-cool? [o] (or (instance? Cool1 o) (instance? Cool2 o))
or, (even worse)
(defn is-this-cool? [o] (and (satisfies? OnlyHalfCoolness o)
(instance? Comparable o) (instance? Serializable o))

A type hierarchy is not required - but I think a way to compose
(atleast union) abstractions would be nice.

Are there some fundamental problems with - (defprotocol Coolness ..
Comparable .. Serializable .. x y z) ?

> What do you mean by "static" functions?

Normal functions which do not dispatch based on the type of their
first argument. Forget about this - thinking more about it - they
don't really make too much sense in protocols.


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