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

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


module IO (hGetChar,cHGetChar) where

import NHC.Internal (IO(..))
import DIOError
import DHandle

{-
The world ensures correct sequentialisation of IO-actions,
especially avoids sharing of input actions.
However, the world is not passed everywhere and the following
code relies on nhc not perform optimisations that could
change the evaluation order.
E.g., don't use `const' instead of the lambda abstraction of world.
-}

import PreludeBuiltin(_hGetChar)

hGetChar              :: Handle -> IO Char
hGetChar h    = IO (\world -> input h)
 where
  input h = let c = cHGetChar h
            in if c < 0 then
                 Left (EOFError "hGetChar" h)
               else
                 Right (toEnum c)

cHGetChar :: Handle -> Int
cHGetChar h = _hGetChar h		-- _hGetChar -> special bytecode



Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.