3 ms·
Without this syntactic sugar, monadic code rarely looks like an elegant solution. I'm not sure this is widely agreed-upon. Here's what a program composed of p
by jrockway 16y ago
Without this syntactic sugar, monadic code rarely looks like an elegant solution.
I'm not sure this is widely agreed-upon. Here's what a program composed of pure functions looks like:
quux = baz . bar . foo
This is a function of one argument that filters the input through foo, then bar, then baz. Just like UNIX pipes, but backwards.
Now let's try it with monads:
quux = baz =<< bar =<< foo
Same thing; this is a function of one argument, one that passes that argument through foo, then bar, then baz.
>>= notation is quite elegant. do notation just makes functional programing look imperative.