Skip to content

Instantly share code, notes, and snippets.

@KiJeong-Lim
Created June 13, 2021 07:53
Show Gist options
  • Save KiJeong-Lim/ed4bdf387db4842c63d40e6bc45f49b1 to your computer and use it in GitHub Desktop.
Save KiJeong-Lim/ed4bdf387db4842c63d40e6bc45f49b1 to your computer and use it in GitHub Desktop.
module Main where
import System.IO
infixl 1 <<
class OStream os where
mkOStream :: os -> IO Handle
class OStreamObject a where
intoString :: a -> String
instance OStream Handle where
mkOStream = pure
instance OStream a => OStream (IO a) where
mkOStream ma = ma >>= mkOStream
instance OStreamObject Char where
intoString ch = return ch
instance OStreamObject a => OStreamObject [a] where
intoString xs = xs >>= intoString
instance OStreamObject Int where
intoString i = shows i ""
cout :: Handle
cout = stdout
cerr :: Handle
cerr = stderr
endl :: Char
endl = '\n'
(<<) :: (OStream os, OStreamObject a) => os -> a -> IO Handle
os << x = do
h <- mkOStream os
hPutStr h (intoString x)
return h
int :: Integral a => a -> Int
int = fromInteger . toInteger
main :: IO ()
main = do
cout << "Hello world!" << endl
cout << (int)1234 << ' ' << (int)5678 << endl
return ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment