On Apr 15, 2009, at 14:28, Meikel Brandmeyer wrote: >> As an example, take algebraic data types as defined in >> clojure.contrib.types. A simple binary tree structure can be defined >> with >> >> (defadt ::tree >> empty-tree >> (leaf value) >> (node left-tree right-tree)) >> >> Values of this type are represented as maps in which the value >> associated with :clojure.contrib.types/tag is the constructor >> (`empty- >> tree, `leaf, or `node), with the :type in the metadata being ::tree. >> This double labelling makes sure that all tree values are recognized >> as being of the same type in dispatching, but also that equality >> tests take into account the constructor in addition to its arguments. > > Maybe I'm missing something, but we can't you just derive > ::leaf, ::empty-tree and ::node from ::tree? You can use ::tree in > dispatch values, but the map still contains the constructor...
I could give each constructor a separate type and derive them all from the base type. That would blow up the hierarchy with lots of types that are not really needed for dispatching, but in this situation it is an implementation option. In the opposite scenario, where types ::b and ::c derive from ::a but all varieties of ::a should test as equal, this option is no longer there: you have to put ::a in the data and ::b or ::c in the metadata. I thus prefer to consider dispatching and equality testing entirely independent, which lead me to choose the arrangement I described for algebraic data types. 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 -~----------~----~----~----~------~----~------~--~---