Skip to content

Instantly share code, notes, and snippets.

@kbridge
Created October 1, 2021 14:40
Show Gist options
  • Save kbridge/3ab70e06d2f37fb9718e99aba04797ce to your computer and use it in GitHub Desktop.
Save kbridge/3ab70e06d2f37fb9718e99aba04797ce to your computer and use it in GitHub Desktop.
import Data.IORef
newCounter :: IO (IO Int)
newCounter = do
n <- newIORef 0
return $ do
modifyIORef' n (+1)
readIORef n
-- GHCi:
--
-- a <- newCounter
-- a
-- a
-- a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment