Skip to content

Instantly share code, notes, and snippets.

@thalesmg
Last active January 13, 2017 12:19
Show Gist options
  • Save thalesmg/ba9a901d3f7485888ee1470404781b20 to your computer and use it in GitHub Desktop.
Save thalesmg/ba9a901d3f7485888ee1470404781b20 to your computer and use it in GitHub Desktop.
Studying polyvariadicity in Haskell
{-# LANGUAGE FlexibleInstances #-}
class C a where
-- Tipo Args -> Tipo Acumulador -> C a
boom :: String -> a
-- |Tipo final
instance C String where
boom = id
-- instance C a => C (String -> a) where
-- boom acc a = boom (acc ++ " " ++ a)
instance (Show x, C a) => C (x -> a) where
boom acc a = boom (acc ++ " " ++ show a)
kaboom :: (C a, Show x) => x -> a
kaboom = boom ""
main :: IO ()
main = do
putStrLn $ boom "asdfs" True (Just 'c') 23242
putStrLn $ boom "asasdlf" "dlskfs"
putStrLn $ kaboom "asasdlf" "dlskfs" True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment