Paste number 33254: Simple IORef example.

Paste number 33254: Simple IORef example.
Pasted by: Cale
When:12 years, 6 months ago
Share:Tweet this! |
Paste contents:
Raw Source | XML | Display As
import Data.IORef

mainLoop ref = do
    putStrLn "Enter a value to set the IORef to, or blank to print it."
    x <- getLine
    if null x
        then do v <- readIORef ref
                print v
        else writeIORef ref x
    mainLoop ref

main = do
    ref <- newIORef "Initial value."
    mainLoop ref 

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.