Created
May 25, 2018 20:37
-
-
Save parsonsmatt/266ceb25eb3a1b680815a49f47c54b5b 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 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