Skip to content

Instantly share code, notes, and snippets.

@bitonic
Created November 1, 2011 19:23
Show Gist options
  • Save bitonic/1331621 to your computer and use it in GitHub Desktop.
Save bitonic/1331621 to your computer and use it in GitHub Desktop.
cout in Haskell
{-# 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