Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/IO/HPutStr.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module IO (hPutStr) where

import DHandle
import HPutChar

-- This is the definitely working, but inefficient, version.
hPutStr               :: Handle -> String -> IO ()
hPutStr h []           = return ()
hPutStr h (x:xs)       = hPutChar h x >> hPutStr h xs


{-
-- This version does string-packing in chunks on the
-- C-side, improving the performance no matter how large
-- the string is.

-- We cannot yet use this when dealing with traced strings -
-- they have a different data representation that needs to be
-- coded explicitly in C.

foreign import ccall "hPutStrC" hPutStrC :: Handle -> String -> IO ()

hPutStr               :: Handle -> String -> IO ()
hPutStr h []           = return ()
hPutStr h xs@(x:_)     = hPutStrC h xs

-- Note: we rely on pattern-matching here to force the evaluation of
-- the first cons in the string - for some unknown reason this is
-- important for the runtime system.  The obvious simple alternative:
--      hPutStr = hPutStrC
-- gives an "unevaluated tag in TABLESWITCH" runtime crash.

-}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].