Skip to content

Instantly share code, notes, and snippets.

@cympfh
Last active December 20, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cympfh/6210557 to your computer and use it in GitHub Desktop.
Save cympfh/6210557 to your computer and use it in GitHub Desktop.
可変長引数の実験
{-# 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