Search code examples
clojurealgebraic-data-types

Clojure algebraic data types


I've found defadt macro in clojure.contrib.types. Unfortunately, there is no useful documentation on ADTs usage in clojure. I've googled for hours and found tiny pieces of information about it. What are ADTs in clojure? How to use them? Any information will be helpful :)


Solution

  • Some information can be found in the examples.clj file in src/clojure/contrib/types. It shows an example of a tree structure defined as an adt:

    (defadt ::tree
      empty-tree
      (leaf value)
      (node left-tree right-tree))
    

    More info in the source file.