[Haskell-cafe] Re: Exception: Too many open files
benjamin.franksen at bessy.de
Tue Oct 24 07:27:56 EDT 2006
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 .
> 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.
More information about the Haskell-Cafe