Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Monads and Macros operate at different levels of abstraction. </p> <p>I think of macros as "code monkeys": anytime I find myself writing a lot of boilerplate, I take a moment and think whether macros can help.</p> <p>Monads on the other hand are very powerful abstractions generally used in order to isolate and compose side effects in a purely functional setting. (I'm not an expert on Monads so take this with a grain of salt).</p> <p>The bottom line is that I think they are solving fundamentally different problems.</p> <p>If we take the example you provided, writing a Redis driver, any function accessing the network is a candidate for an abstraction through monads - in this case, both the IO and Maybe (or Either) monads. But not because of repetition, but rather because your functions have side effects.</p> <p>Now this is where Monads in clojure can get harder than it's worth: If you want to compose both monads, you need to use <a href="http://en.wikibooks.org/wiki/Haskell/Monad_transformers" rel="nofollow">monad transformers</a>. Obviously this is not enforced by clojure since it's a dynamic language so one can argue debugging composed monadic code in a dynamic language can be very hard. A static type system such as Haskell's would be of great help here.</p> <p>So while a redis driver can definitely be written in a monadic style, I believe the point Aaron is making in the presentation is avoiding repetition, and for that, I believe macros are a better fit in Clojure.</p> <p>I hope this is helpful.</p> <p><strong>EDIT</strong>:</p> <p>I should also node that monads in Clojure would be hardly useful without the Haskell inspired <em>do</em> notation which is essentially made possible by macros, providing further proof that macros are at a different level of abstraction. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload