Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Last active December 18, 2015 20:59
Show Gist options
  • Save PatrickJS/5844343 to your computer and use it in GitHub Desktop.
Save PatrickJS/5844343 to your computer and use it in GitHub Desktop.
Identity Monad - Take a value and give the value back with bind.
function MONAD() {
return function unit(value) {
var monad = Object.create(null);
monad.bind = function(func) {
return func(value);
};
return monad;
};
}
=== Axioms ===
--function way--
bind(bind(monad, f), g)
monad.bind(f).bind(g)
--method way--
unit(value).bind(f) ==== f(value
monad.bind(unit) ==== monad
monad.bind(f).bind(g) ==== monad.bind(function(value) {
return f(value).bind(g);
};
============
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment