Created
January 18, 2013 14:05
-
-
Save danhodge/4564735 to your computer and use it in GitHub Desktop.
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
class Monad | |
def self.unit(value) | |
monad = new | |
monad.define_singleton_method(:bind) { |func, *args| func.call(*([value] + args)) } | |
monad | |
end | |
def lift(name, func, *args) | |
define_singleton_method(name) { Monad.unit(bind(func, args)) } | |
self | |
end | |
end | |
identity = Monad.unit("Hello World") | |
identity.bind(lambda { |arg| puts arg }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment