Bas van Dijk wrote:
> On Monday 23 October 2006 21:50, Tomasz Zielonka wrote:
>> unsafeInterleaveMapIO f (x:xs) = unsafeInterleaveIO $ do
>>         y <- f x
>>         ys <- unsafeInterleaveMapIO f xs
>>         return (y : ys)
>>     unsafeInterleaveMapIO _ [] = return []
> 
> Great it works! I didn't know about unsafeInterleaveIO [1].
> 
> Why is it called 'unsafe'?

Because it causes pure code to perform side-effects (=IO), albeit in a
controlled manner, so it's not as bad as unsafePerformIO. For instance,
using getContents you get a string (list of chars) with the property that
evaluating subsequent elements of the list causes IO to happen (in this
case reading another character from stdin). Thus, unsafeInterleaveIO is
safe only if it is not observable (from inside the program) when exactly
the IO gets performed.

Ben

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to