
Hi
Thanks to dcoutts, I have now come up with an answer. I don't
understand why it works now, but not before. I do remember than
browsing either Core or STG is not a fun thing to do...
p_System_IO_hGetChar h = trace "i am here" $
unsafePerformIO $ getCharIO h
{-# NOINLINE getCharIO #-}
getCharIO h = do
c <- getchar
print c
return $ if c == (-1) then 0 else chr_ c
Thanks
Neil
On 5/2/07, Neil Mitchell
Hi Bulat,
Wednesday, May 2, 2007, 7:00:05 PM, you wrote:
{-# NOINLINE wrapIO #-} wrapIO x = unsafePerformIO (x >>= return)
-fno-cse ? it's usual company for unsafePerformIO+NOINLINE :)
No luck, alas. A slightly tweaked version, which is slightly simpler and still gives the same behaviour is below.
Thanks
Neil
----------------------
main = p_System_IO_hGetChar undefined `seq` p_System_IO_hGetChar 12 `seq` putStrLn "done"
foreign import ccall "stdio.h getchar" getchar :: IO Word8
{-# NOINLINE p_System_IO_hGetChar #-} p_System_IO_hGetChar h = trace "i am here" $ unsafePerformIO (getchar >>= \c -> print c >> return (if c == (-1) then 0 else chr_ c))
chr_ = fromEnum