Skip to content

Instantly share code, notes, and snippets.

@apskii
Last active December 22, 2015 14:39
Show Gist options
  • Save apskii/6487547 to your computer and use it in GitHub Desktop.
Save apskii/6487547 to your computer and use it in GitHub Desktop.
(defstruct monad lift bind)
(defconstant +id-monad+
(make-monad
:lift #'identity
:bind (lambda (x f) (funcall f x))))
(defconstant +list-monad+
(make-monad
:lift #'list
:bind (lambda (xs f) (mapcan f xs))))
(defconstant +nil-monad+
(make-monad
:lift #'identity
:bind (lambda (mx f) (if mx (funcall f mx) mx))))
(defvar *monad* +id-monad+)
(defun ret (x)
(funcall (monad-lift *monad*) x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment