Created
September 30, 2016 16:53
-
-
Save raichoo/c524860b3b920e541cc6aa3a2a893ffe to your computer and use it in GitHub Desktop.
Haskell Example
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
module Assign where | |
import Data.IORef | |
mkSummer :: IO (Int -> Int -> IO Int) | |
mkSummer = do | |
ref <- newIORef 0 | |
return $ \x y -> do | |
val <- readIORef ref | |
let ret = val + x + y | |
writeIORef ref ret | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a purer version of the idea using
StateT
(I'm mainly using the Transformer to print the intermediate results).