3 ms·
It's a pretty common pattern, I think it's worth its own word, at least as much as mapM: mapM f xs = sequence (map f xs) replicateM n x = sequence
by jewbacca 14y ago
It's a pretty common pattern, I think it's worth its own word, at least as much as mapM:
mapM f xs = sequence (map f xs)
replicateM n x = sequence (replicate n x)
Another cool thing replicateM is equivalent to: for lists, it's the cartesian power (sequence is the cartesian product). ...this is actually the primary reason I'm aware of it.