I know the question has been asked there but I can't believe there is no straight answer.
I understand it's not good to hide side-effect inside a (&&) but in my case the side-effect are just checking something in the outstide world (existence of a file, check modification time etc, ask user a yes/no quistion).
So what is the haskell way to something like this, so that cond2 is not executed if cond1 is false.
cond1, cond2 :: IO bool
main = do
cond <- liftM2 (&&) con1 con2
if cond
then result1
else result2
I was expecting something like cond <- all [con1, con2]
or equivalent, but I can't find anything.
Update
I can see lots of manual solution. I'm still puzzled that this function doesn't exists somewhere.
One advantage of lazzy evaluation is it doesn't only short-circuit for hard-coded &&
like in C. It is really strange that when in imperative mode, Haskell can't even short-circuit &&
.
Although, all solution use somehow and if to short-circuit the evaluation. Is there not a way to make a generic lazzy liftM2
?