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

Roman Cheplyaka roma at ro-che.info
Thu Oct 30 13:50:02 UTC 2014


On 30/10/14 15:42, Semen Trygubenko / Семен Тригубенко wrote:
> Dear Haskell-Cafe,
> 
> Is there a way to get Control.Applicative.<|> to short-circuit when combining two IO actions?
> 
> E.g.
> 
>> let a = putStrLn "A" >> return (Left "hehe")
>> let b = putStrLn "B" >> return (Right 42)
> 
>> Prelude> liftA2 (<|>) a b
> 
> A
> B
> Right 42
> 
>> 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

Roman

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20141030/262074ab/attachment.sig>


More information about the Haskell-Cafe mailing list