Skip to content

Instantly share code, notes, and snippets.

@zeusdeux
Created May 17, 2018 13:02
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 zeusdeux/632d105758b193f82f9c68d46df0b9b9 to your computer and use it in GitHub Desktop.
Save zeusdeux/632d105758b193f82f9c68d46df0b9b9 to your computer and use it in GitHub Desktop.
Variadic function type in haskell
class Foo t where
returnLast :: Int -> t
class Integral i => IntsBro i where
toInt :: i -> Int
instance IntsBro Integer where
-- toInt :: Integer -> Int
toInt i = fromIntegral i :: Int
instance Foo Int where
-- returnLast :: Int -> Int
returnLast = id
instance (IntsBro a, Foo b) => Foo (a -> b) where
-- returnLast :: Int -> a -> b
returnLast _ = returnLast . toInt . toInteger
returnLast 1 2 3 4 :: Int --will return 4
returnLast 1 2 :: Int --will return 2, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment