Last active
December 21, 2015 01:58
-
-
Save cympfh/6231538 to your computer and use it in GitHub Desktop.
可変数引数の実験, format (可変String -> IO())
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 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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello, world!
sum of [1,2,3,4,5,6,7,8,9,10] is 55.