Last active
December 20, 2015 23:09
-
-
Save cympfh/6210557 to your computer and use it in GitHub Desktop.
可変長引数の実験
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 t where | |
hoge :: [Int] -> t | |
instance PType Int where | |
hoge = sum | |
instance PType r => PType (Int -> r) where | |
hoge xs = (\x -> hoge $ x:xs) | |
total :: PType r => r | |
total = hoge [] | |
main = do | |
print $ (total :: Int) | |
print $ (total (1 :: Int) :: Int) | |
print $ (total (1 :: Int) (2 :: Int) :: Int) | |
print $ (total (1 :: Int) (2 :: Int) (10 :: Int) :: Int) | |
print $ (total (1 :: Int) (2 :: Int) (10 :: Int) (100 :: Int) :: Int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment