[Haskell-cafe] Lazy IO with recursive reads?

Stephen Tetley stephen.tetley at gmail.com
Wed Feb 24 16:41:14 EST 2010


Hi Fabian

>From the source viewable in the Haddock docs supplied with GHC

- hGetContents calls lazyRead:

hGetContents :: Handle -> IO String
hGetContents handle =
   wantReadableHandle "hGetContents" handle $ \handle_ -> do
      xs <- lazyRead handle
      return (handle_{ haType=SemiClosedHandle}, xs )

- lazyRead :

lazyRead :: Handle -> IO String
lazyRead handle =
   unsafeInterleaveIO $
        <<stuff>>

hGetContents is using unsafeInterleaveIO already so you don't have to.

Best wishes

Stephen


More information about the Haskell-Cafe mailing list