clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
Yosevu Kilonzo 2019-11-30T05:06:06.127100Z

Hello, I think I have a podcasty question! I'm new to Clojure and wondering: is it useful to study Algebraic Data Types? do people use them in Clojure? How do or don't they fit in with the Clojure language and philosophy?

neumann 2019-12-02T16:25:41.128500Z

@yosevuk Welcome to the channel! I am of the opinion you can get quite a lot done without studying the theory of functional programming. Much of the published theory relates to type systems, and isn't as necessary in Clojure as it is in languages such as Haskell.

neumann 2019-12-02T16:28:26.128700Z

Personally, I find the theory very interesting, but I don't think it's very helpful for getting started in functional programming. Clojure allows you to be quite productive without having to learn a bunch of theory.

neumann 2019-12-02T16:38:17.129Z

Clojure doesn't support Algebraic Data Types as a feature of the language because Clojure isn't statically typed (like Haskell). However, Clojure is strongly typed and it allows you to create new types using defrecord and deftype. You can then match on those types in a multimethod. Basically, you can have a similar style of programming as Haskell, but it isn't strictly necessary to approach things that way in Clojure.

neumann 2019-12-02T16:43:47.129200Z

For example, in the class tree ADT, instead of having an Empty, Leaf, and Node type, you can use tuple like lists: [:empty], [:leaf value], [:node left-tree right-tree].

neumann 2019-12-02T17:02:32.129400Z

Then you can dispatch on the keyword: (defmulti tree-function first)

Yosevu Kilonzo 2019-12-10T18:24:41.170800Z

Ah, so as I understand, algebraic types aren't a feature, but the langauge does provide the tools to program in that style if you really want to. Thanks for that context @neumann! I have to read more about datatypes and multimethods.

neumann 2019-12-10T18:30:15.171Z

@yosevuk That sounds like a great summary. You're welcome!