[Haskell-cafe] is the evaluation order deterministic when using applicative with IO

Dmitry Olshansky olshanskydr at gmail.com
Fri Mar 16 12:33:19 CET 2012


As usual you can check:

Prelude Control.Applicative> pure (||) <*> pure True <*> undefined
*** Exception: Prelude.undefined

Prelude Control.Applicative> (||) True undefined
True



2012/3/16 Rouan van Dalen <rvdalen at yahoo.co.uk>

> Hi everyone.
>
> I was wondering if I can make assumptions about the evaluation order of
> the following code:
>
> isTrue :: Int -> IO Bool
> isTrue val = pure (||) <*> boolTest1 val <*> boolTest2 val
>
>
> {- boolTest1 is an inexpensive, quick check -}
> boolTest1 :: Int -> IO Bool
> boolTest1 val = undefined
>
>
> {- boolTest2 is a very expensive check -}
> boolTest2 :: Int -> IO Bool
> boolTest2 val = undefined
>
>
> When using Applicative in the isTrue function, I would like to make use of
> the short-circuit behaviour of || and rely on the fact that the boolTest1
> will be executed first.  The reason I am asking is because the boolTest
> functions
> are in the IO monad, instead of just returning pure Bool values.
>
> Regards
> Rouan.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120316/4dfd22fa/attachment.htm>


More information about the Haskell-Cafe mailing list