Define a monad transforer in terms of the monad operations and the base
monad. The argument which-m-plus chooses if m-zero and m-plus are taken
from the base monad or from the transformer.
(defmacro monad-transformer
"Define a monad transforer in terms of the monad operations and the base
monad. The argument which-m-plus chooses if m-zero and m-plus are taken
from the base monad or from the transformer."
[base which-m-plus operations]
`(let [which-m-plus# (cond (= ~which-m-plus :m-plus-default)
(if (= ::undefined (with-monad ~base ~'m-plus))
:m-plus-from-transformer
:m-plus-from-base)
(or (= ~which-m-plus :m-plus-from-base)
(= ~which-m-plus :m-plus-from-transformer))
~which-m-plus
:else
(throw (java.lang.IllegalArgumentException.
"undefined m-plus choice")))
combined-monad# (monad ~operations)]
(if (= which-m-plus# :m-plus-from-base)
(assoc combined-monad#
:m-zero (with-monad ~base ~'m-zero)
:m-plus (with-monad ~base ~'m-plus))
combined-monad#)))
Comments top
No comments for monad-transformer. Log in to add a comment.