Last active
December 18, 2015 20:59
-
-
Save PatrickJS/5844343 to your computer and use it in GitHub Desktop.
Identity Monad - Take a value and give the value back with bind.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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