|
|
|
|
|
by mrkgnao
3247 days ago
|
|
The unpleasantness arises when writing Monad instances that don't follow the laws. Setting your disingenuity aside, try using xs >>= f = concat (reverse (map f xs))
or Array.prototype.chain = function (f) {
return reverse(this.reduce((acc, it) => acc.concat(f(it)), []))
}
(I don't know how JS works, but you get it) instead of xs >>= f = concat (map f xs)
and enjoy refactoring your code, blissfully and consciously ignorant of the laws that make a monad a monad. The laws aren't just supposed to enrich the "life of the mind". |
|