Skip to content

Instantly share code, notes, and snippets.

@thefloweringash
Created November 4, 2013 05:13
Show Gist options
  • Save thefloweringash/7298326 to your computer and use it in GitHub Desktop.
Save thefloweringash/7298326 to your computer and use it in GitHub Desktop.
Why not Haskell syntax?
(ns gist.monad
(use [clojure.algo.monads :only [domonad]]))
(def <-)
(defn transform-monad-syntax [body last-was-assign]
(let [[v o e & r] body]
(cond (empty? body)
(if last-was-assign
(throw (IllegalArgumentException. "last value in m-do must be expression"))
[])
(= o '<-)
(concat [v e] (transform-monad-syntax r true))
:else
(concat ['_ v] (transform-monad-syntax (rest body) false)))))
(defmacro m-do [monad & body]
`(domonad ~monad
~(vec (transform-monad-syntax body false))
~(last body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment