あらゆる意味におけるコメントを強く強く希望します。
comp.lang.functional で拾ったネタです.
print
, show
では,2バイト文字を表示できませんが,putStr
, putStrLn
では表示可能です.
primitive putStr :: String -> IO () print :: Show a => a -> IO () print = putStrLn . show putStrLn :: String -> IO () putStrLn s = do putStr s putChar '\n' hugsPutStr :: String -> IO () hugsPutStr = putStr class Show a where show :: a -> String showsPrec :: Int -> a -> ShowS showList :: [a] -> ShowS -- Minimal complete definition: show or showsPrec show x = showsPrec 0 x "" showsPrec _ x s = show x ++ s showList [] = showString "[]" showList (x:xs) = showChar '[' . shows x . showl xs where showl [] = showChar ']' showl (x:xs) = showChar ',' . shows x . showl xs
Haskell 98 mode: Restart with command line option -98 to enable extensions Reading file "Krause:usr:lang:Haskell:Hugs 98:lib:Prelude.hs": Hugs session for: Krause:usr:lang:Haskell:Hugs 98:lib:Prelude.hs Type :? for help Prelude> print "" "" (26 reductions, 48 cells) Prelude> print "abcv" "abcv" (97 reductions, 151 cells) Prelude> print "あいうえお" "\130\160\130\162\130\164\130\166\130\168" (407 reductions, 598 cells) Prelude> Prelude> show "" "\"\"" (36 reductions, 64 cells) Prelude> show "abc" "\"abc\"" (142 reductions, 220 cells) Prelude> show "あいうえお" "\"\\130\\160\\130\\162\\130\\164\\130\\166\\130\\168\"" (1076 reductions, 1522 cells) Prelude> Prelude> putStr "" (6 reductions, 8 cells) Prelude> putStr "abc" abc (6 reductions, 11 cells) Prelude> putStr "あいうおえ" あいうおえ (6 reductions, 18 cells) Prelude> Prelude> putStrLn "" (13 reductions, 25 cells) Prelude> putStrLn "abc" abc (12 reductions, 20 cells) Prelude> putStrLn "あいうえお" あいうえお (12 reductions, 27 cells) Prelude> Prelude> hugsPutStr "" ERROR: Unrecognised character `\129' in column 11 Prelude> hugsPutStr "abc" abc (6 reductions, 11 cells) Prelude> hugsPutStr "あいうえお" あいうえお (6 reductions, 18 cells) Prelude>