|
|
|
|
|
by lmm
2517 days ago
|
|
It needs to be associative. More concretely, if you want to have something like "do notation" that makes sense, so that you can write code like: x <- f(a)
y <- g(b)
z <- h(c)
for composition, then it needs to be the case that x.flatMap(a => f(a)).flatMap(b => g(b)) is equivalent to x.flatMap(a => f(a).flatMap(b => g(b))). Unfortunately people sometimes implement a flatMap where these are almost, but not quite, equivalent, which leads to very confusing behaviour and subtle bugs.You also need to be able to "point" a pure value and have the equivalences you'd expect - this often ends up being important as e.g. the base case of a recursive function. |
|