[Haskell-cafe] Lazy Evaluation in Monads
Artyom Kazak
artyom.kazak at gmail.com
Tue May 31 22:48:17 CEST 2011
Scott Lawrence <bytbox at gmail.com> писал(а) в своём письме Tue, 31 May 2011
23:29:49 +0300:
> On 05/31/2011 04:20 PM, Artyom Kazak wrote:
>> Suppose iRecurse looks like this:
>> iRecurse = do
>> x <- launchMissiles
>> r <- iRecurse
>> return 1
>>
>> As x is never needed, launchMissiles will never execute. It obviously is
>> not what is needed.
> Prelude> let launchMissiles = putStrLn "UH OH" >> return 1
> Prelude> let iRecurse = launchMissiles >> return 1
> Prelude> iRecurse
> UH OH
> 1
> Prelude>
> Looks like launchMissiles /does/ execute, even though x is (obviously)
> never needed.
Oh, sorry. I was unclear. I have meant "assuming IO is lazy", as Yves
wrote.
And saying "some hacks" I meant unsafeInterleaveIO, which lies beneath the
laziness of, for example, getContents.
More information about the Haskell-Cafe
mailing list