reset password
Author Message
kmarlis
Posts: 35
Posted 10:59 Apr 05, 2019 |

Hey everyone!

I just wrote up a fairly lengthy post about having trouble chaining together bind s(using the Monad/Maybe implementation from the prompt) for the Walk the Line implementation, and right before I hit submit I remembered curry from toolz. It solved my problem splendidly and I just thought I'd put that out there in case anyone else has trouble.

jpatel77
Posts: 44
Posted 11:02 Apr 05, 2019 |

Toolz is the 8th wonder for Python. Just so good.

rabbott
Posts: 1649
Posted 12:27 Apr 05, 2019 |

Soo pointed out that curry can also be imported from pymonad.Reader

from pymonad.Reader import curry

PyMonad really is self-contained.

Last edited by rabbott at 12:28 Apr 05, 2019.
rabbott
Posts: 1649
Posted 12:48 Apr 05, 2019 |

DeLaat provides a nice write-up of PyMonad on its pypi page.

The discussion of the State Monad (near the bottom of the page) chains two functions, modified versions of add and subtract, each with the usual two arguments. As Kevin implied, the functions must be curried to be chained.

@curry
def add(x, y):
        ...

@curry
def subtract(y, x): 
        ...
x = unit(State, 1) >> add(2) >> add(3) >> subtract(40) >> add(5)

You should look at the entire example. (It's short.)

 

Last edited by rabbott at 12:50 Apr 05, 2019.