So I have these two functions:
filterM _ [] = []
filterM p (x:xs) = do
n <- p x
ys <- filterM p xs
return (if n then x:ys else x:xs)
and
filterM _ [] = return []
filterM p (x:xs) = do
n <- p x
ys <- filterM p xs
return (if n then x:ys else x:xs)
Resulting in these results for the following input: filterM (\x -> [True,False]) [0..3]
[]
or
[[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3],[0,1,2,3]]
Why does return impact the execution so much?