Created
June 13, 2021 07:53
-
-
Save KiJeong-Lim/ed4bdf387db4842c63d40e6bc45f49b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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