On 01/12/2012 07:53 PM, Serge D. Mechveliani wrote:
[...]
>
For the "to-A" part writen in C (instead of Haskell), this interface
loop works all right.
With Haskell, I manage to process only a single string in the loop,
and then it ends with an error.
Main.hs is given below.
I never dealt with such an IO in Haskell.
Can you, please, fix the code or give comments?
Please, copy the response to mech...@botik.ru
(I am not in the list).
[...]
-------------------------------------------------------------------
import System.IO (IOMode(..), IO(..), Handle, openFile, hPutStr,
hGetLine, hFlush)
import System.IO.Unsafe (unsafePerformIO)
dir = showString "/home/mechvel/ghc/axiomInterface/byLowerLevel/"
toA_IO = openFile (dir "toA") WriteMode :: IO Handle
fromA_IO = openFile (dir "fromA") ReadMode
-- used as global values
toA = unsafePerformIO toA_IO --
fromA = unsafePerformIO fromA_IO --
axiomIO :: String -> IO String
axiomIO str = do
hPutStr toA str
hFlush toA
hGetLine fromA
axiom :: String -> String -> String
axiom str = showString (unsafePerformIO $ axiomIO str)
-- Examples of usage --------------------------------------------
tl;dr, but did you try to write your program without using
unsafePerformIO? It's "considered harmful" for a reason.
Cheers, Steffen
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe