Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
Created May 25, 2018 20:37
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 parsonsmatt/266ceb25eb3a1b680815a49f47c54b5b to your computer and use it in GitHub Desktop.
Save parsonsmatt/266ceb25eb3a1b680815a49f47c54b5b to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExistentialQuantification #-}
data Adder = forall a. Adder
{ increment :: a -> a
, render :: a -> String
, value :: a
}
main :: IO ()
main = do
let adder = Adder
{ increment = (+ 1)
, render = show
, value = 0 :: Int
}
runAdder adder
runAdder :: Adder -> IO ()
runAdder (Adder increment render value) =
putStrLn . render . increment . increment $ value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment