class Monad:
def __init__(self, val):
self.val = val
unit = __init__
def bind(self, fun):
return fun(self.val)
Now, in the case of our ruby and python examples respectively, there is no sane way of enforcing typing, but if it works out, it looks to me like that at least implements the monad interface. Not so sure how all the laws work out...But interestingly we could implement lift as a Monad method by:
def lift(self, fun=lambda x: x*2):
self.val = fun(self.val)
return self
unless I really don't get all this.