/  22
 
A Wander through GHC’sNew IO library
Simon Marlow
 
 The 100-mile view
the API changes:
 –
Unicode
putStr “A légpárnás hajóm tele vanangolnákkal” works! (if your editor is set upright…)
locale-encoding by default, except forHandles in binary mode (openBinaryFile,hSetBinaryMode)
changing the encoding on the fly
 
hSetEncoding :: Handle -> TextEncoding -> IO ()hGetEncoding :: Handle -> IO (Maybe TextEncoding)
data
TextEncodinglatin1, utf8, utf16, utf32, … :: TextEncodingmkTextEncoding :: String -> IO TextEncodinglocaleEncoding :: TextEncoding
 
 The 100-mile view (cont.)
Better newline support
 –
teletypes needed bothCR+LF to start a newline, and we’ve been
hSetNewlineMode :: Handle -> NewlineMode -> IO ()
data
Newline = LF {- “\n” –} | CRLF {- “\r\n” -}nativeNewline :: Newline
data
NewlineMode = NewlineMode {inputNL :: Newline,outputNL :: Newline }noNewlineTranslation = NewlineMode { inputNL = LF, outputNL = LF }universalNewlineMode = NewlineMode { inputNL = CRLF, outputNL =nativeNewline }nativeNewlineMode = NewlineMode { inputNL = nativeNewline,outputNL = nativeNewline }

Share & Embed

More from this user

Add a Comment

Characters: ...