[Haskell-cafe] named pipe interface
Serge D. Mechveliani
mechvel at botik.ru
Mon Jan 16 13:01:41 CET 2012
To my question about safety of
>> toA_IO = openFd "toA" WriteOnly Nothing defaultFileFlags
>> fromA_IO = openFd "fromA" ReadOnly Nothing defaultFileFlags
>> toA = unsafePerformIO toA_IO
>> fromA = unsafePerformIO fromA_IO
>>
>> axiomIO :: String -> IO String
>> axiomIO str = do
>> fdWrite toA str
>> (str, _) <- fdRead fromA 64
>> return str
Jean-Marie Gaillourdet wrote on Jan 16, 2012
> [..]
>
> I'd say this use of unsafePerformIO is *not* safe. E.g. a Haskell
> compiler is allowed to evaluate the right hand side of toA and fromA
> multiple times. If you aren't 100% sure that it is ok to use
> unsafePerformIO, don't use it!
> [..]
For example, consider in the above context the program
main = do
(str1, _) <- fdRead fromA 64
(str2, _) <- fdRead fromA 64
putStr (str1 ++ str2)
Is this possible that str1 and str2 are input from different file
descriptors?
Does this effect depend on in-lining of fromA_IO by the compiler ?
Will {-# NOTINLINE "fromA_IO" #-} make it safe?
Please, copy the respond to mechvel at botik.ru
Regards,
------
Sergei
mechvel at botik.ru
More information about the Haskell-Cafe
mailing list