[Haskell-cafe] <|> that short-circuits in IO ?

Roman Cheplyaka roma at ro-che.info
Sat Nov 1 10:38:57 UTC 2014


On 31/10/14 23:22, Kim-Ee Yeoh wrote:
> On Thu, Oct 30, 2014 at 8:50 PM, Roman Cheplyaka <roma at ro-che.info> wrote:
> 
>>>> liftA2 (<|>) b a
>>>
>>> B
>>> A
>>> Right 42
>>>
>>> (In the latter case I don't want A in the output…)
>>
>> Wrap it into ExceptT (from the latest transformers), as in
>>
>>   runExceptT $ ExceptT a <|> ExceptT b
> 
> 
> With the latest transformers, I still get
> 
> B
> A
> Right 42
> 
> i.e. the A hasn't been eliminated.
> 
> What am I missing?

I don't know what you're missing, but when I run the following code, it
doesn't print A.

  import Control.Monad.Except
  import Control.Applicative

  a = putStrLn "A" >> return (Left "hehe")
  b = putStrLn "B" >> return (Right 42)

  main = runExceptT $ ExceptT b <|> ExceptT a

Roman


More information about the Haskell-Cafe mailing list