Created
November 1, 2011 19:23
-
-
Save bitonic/1331621 to your computer and use it in GitHub Desktop.
cout in Haskell
This file contains 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
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, IncoherentInstances #-} | |
class Cout a r where | |
(<<) :: IO String -> a -> IO r | |
instance Cout [Char] [Char] where | |
lm << x = fmap (++ x) lm | |
instance Cout [Char] () where | |
lm << x = lm >>= putStr . (++ x) | |
instance Show a => Cout a [Char] where | |
lm << x = fmap (++ show x) lm | |
instance Show a => Cout a () where | |
lm << x = lm >>= putStr . (++ show x) | |
cout :: IO [Char] | |
cout = return "" | |
main :: IO () | |
main = do | |
cout << "Hello world " << 5 << True << "\n" :: IO () | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment