4 ms·
Because for more advanced cases requires flatMap instead of just map and filter. You can only nested as a callback hell instead of streamlined syntactic sugar.
by namelosw 7y ago
Because for more advanced cases requires flatMap instead of just map and filter. You can only nested as a callback hell instead of streamlined syntactic sugar.
Take an example in 'Learn You a Haskell':
[ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2]
b depends on c while a depends on b. You do need a Monadic operation instead of Functor/Applicative to do it because of the dependency in the contexts.
And then you can think of solving the eight queen problem[0]. It's far more readable if you have a syntactic sugar, I just found a Scala example: [1].
[0] https://en.wikipedia.org/wiki/Eight_queens_puzzle https://en.wikipedia.org/wiki/Eight_queens_puzzle
[1] https://stackoverflow.com/questions/42789854/n-queens-in-scala https://stackoverflow.com/questions/42789854/n-queens-in-sca...