I have a list comprehension in Haskell that specifies a predicate on a Maybe type:
[x | x <- listOfMaybes, isJust(f y), x == fromJust(f y)]
is there a way to simplify this expression?
If you simply want to filter out all the Nothings, shang's answer gives the most concise solution. However, it can be done easily in a list comprehension:
[x | Just x <- f y] flip concatMap (f y) $ \result -> case result of {Just x -> [x]; {-Implicitly added!-} _ -> []}Just x <- f y might error
<-, this is not a list comprehension and I doubt it compiles.x==fromJust(f y)in the list comprehension isn't necessary. Conditioning onisJust(f y)does the job.