I know that a question was asked there , but I cannot believe that there is no direct answer.
I understand that it is not good to hide the side effect inside (& &), but in my case the side effect just checks something in the outside world (file presence, time to modify the check, etc., ask the user yes / no quistion).
So what is the haskell way for something like this, so cond2 fails 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 the equivalent, but can't find anything.
Update
I see a lot of manual solutions. I am still puzzled that this feature does not exist. One of the advantages of lazy evaluations is not only the short circuit for hardcoded &&
, as in C. It is very strange that when in imperative mode, Haskell cannot even short-circuit &&
. Although, all solutions are used somehow and, if short-circuited, are estimates. Is there no way to make a general lazy liftM2
?
source share