日本語を含むソースをコンパイル

日本語を扱うのに問題はないが、日本語を含むソースをコンパイルするとエラーになる。utf8-string パッケージのSystem.IO.UTF8を使えばOK。


module Main where
import qualified System.IO.UTF8 as U

main = do
U.putStrLn "あいうえお"

$ ghc --make japanese.hs
[1 of 1] Compiling Main ( japanese.hs, japanese.o )
Linking japanese ...

$ ls japanese*
japanese japanese.hi japanese.hs japanese.o

$ ./japanese
あいうえお

System.IO.UTF8 で定義されているもの。


Prelude> :browse System.IO.UTF8
System.IO.UTF8.appendFile :: FilePath -> String -> IO ()
System.IO.UTF8.getContents :: IO String
System.IO.UTF8.getLine :: IO String
hGetContents :: GHC.IOBase.Handle -> IO String
hGetLine :: GHC.IOBase.Handle -> IO String
hPutStr :: GHC.IOBase.Handle -> String -> IO ()
hPutStrLn :: GHC.IOBase.Handle -> String -> IO ()
System.IO.UTF8.interact :: (String -> String) -> IO ()
openBinaryFile ::
FilePath -> GHC.IOBase.IOMode -> IO GHC.IOBase.Handle
System.IO.UTF8.print :: (Show a) => a -> IO ()
System.IO.UTF8.putStr :: String -> IO ()
System.IO.UTF8.putStrLn :: String -> IO ()
System.IO.UTF8.readFile :: FilePath -> IO String
System.IO.UTF8.readLn :: (Read a) => IO a
withBinaryFile ::
FilePath
-> GHC.IOBase.IOMode
-> (GHC.IOBase.Handle -> IO a)
-> IO a
System.IO.UTF8.writeFile :: FilePath -> String -> IO ()