I usually model sum types as maps with either a :type or :tag key to
specify the kind of map it is.  Occasionally, I use vectors with the tag in
the first position, especially when I need to favor concision, for example,
when the data is serving as a DSL with which I will be manually entering a
lot of data.  I almost never use records for sum types.

Using vectors would be somewhat more useful with core.match, because it is
easy to combine taking cases on the tag with destructuring the correct
number of expected slots after the tag.  I personally don't trust
core.match for serious projects, because it is still in alpha after 7
years.  With regular destructuring, vectors are best for scenarios where
each vector has the same number of slots -- then you can naturally
destructure all the slots of the vector at once in the input to the
function.

I avoid records for this kind of use because: 1. They aren't sufficiently
flexible when the needs of projects change (i.e., everything you can do
with records and protocols you can do with maps and multimethods, but not
vice versa).  2. Records and protocols tend to mess up the state of your
REPL (e.g., when defrecords are recompiled they cause problems with
instance? calls and equality checks to things in memory until your whole
program is recompiled and prior objects thrown away).  3. Until a very
recent 1.9 alpha, records performed poorly in sets or as keys in a map
because they didn't cache their hash values.  4. Use of records and
protocols requires much more careful code organization because it is all
too easy to run afoul of Clojure's lack of support for cyclical
dependencies between namespaces.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to