Open crypticmind opened 5 years ago
somehow the problem is in the @curry
redefining add
as add = lambda x: lambda y: y + x
(like the subtract
example on the README) seems to work fine
returning Reader
seems to be inherent in the implementation of @curry
https://github.com/correl/typesafe-monads/blob/master/monads/currying.py#L16
PyMonad does the same, I guess that is correct
so add
is a Reader
and the xx
,yy
are Result
s
another way that works, with the @curry
'd add function, is:
In [9]: (xx * add) & yy
Out[9]: <Ok 5>
the monad classes here define __mul__ = __rmul__ = map
so I guess the problem is in the precedence of __mul__
vs __rmul__
as described here:
https://stackoverflow.com/a/5182501/202168
(or maybe PyMonad is wrong and there's no reason for @curry
to return a Reader
?)
I really like the idea of typesafe monads in Python (what a time to be alive 😄)
However, I tried this and it doesn't work:
The problem seems to be that
add * xx
callsmap
fromReader
instead ofResult
, and ends up returning a<Reader monads.reader.<lambda>(x)>