Skip to content

Instantly share code, notes, and snippets.

@cympfh
Last active December 21, 2015 01:58
Show Gist options
  • Save cympfh/6231538 to your computer and use it in GitHub Desktop.
Save cympfh/6231538 to your computer and use it in GitHub Desktop.
可変数引数の実験, format (可変String -> IO())
{-# LANGUAGE FlexibleInstances #-}
class PType r where
hoge :: [String] -> r
instance PType (IO ()) where
hoge = putStr . concat . reverse
instance PType String where
hoge = concat . reverse
instance PType r => PType (String -> r) where
hoge xs = \x -> hoge (x : xs)
format :: PType r => r
format = hoge []
(|>) x f = f x
(||>) mx f = mx >>= (return.f)
main = do
format "hello" ", world" "!\n" :: IO ()
format "sum of " (show ls) " is " (show$sum ls) "." |> putStrLn
where
ls = [1 .. 10]
@cympfh
Copy link
Author

cympfh commented Aug 14, 2013

hello, world!
sum of [1,2,3,4,5,6,7,8,9,10] is 55.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment