Hacker News new | ask | show | jobs
by brehaut 5968 days ago
Clojure (being a lisp) uses macros and some dynamic variables to manage this sort of polymorphism. The clojure library provides a defmonad macro to let you define the functions required (m-bind and m-result are a must, and m-plus and m-zero are optional).

Unlike haskell which can choose an implementation based on the return type of return and bind, you do have to spell it out. The macro with-monad will wrap a set of expressions up in the correct monad, and the domonad monad comprehension form is also able to accept an optional monad name (useful if you aren't inside a with-monad form, or if you need a different monad)