3 ms·
I think an easier to understand definition uses fmap and join. Example: f x = [x, x*2] f =<< [5, 3, 4] join (fmap f [5, 3, 4]) join ([[5, 10],
by Tarean 10y ago
I think an easier to understand definition uses fmap and join. Example:
f x = [x, x*2]
f =<< [5, 3, 4]
join (fmap f [5, 3, 4])
join ([[5, 10], [3, 6], [4, 8]])
[5, 10, 3, 6, 4, 8]
So the pattern is fmap a function `a -> f b`; this leaves us with `f (f b)` so we flatten. You might notice that we could bind as often as we want since we always get a list of integers!
- StavrosK 10y agoI think if you already know fmap, join and Haskell syntax, you also already know monads, so I'm not sure whom this is easier for :P