Skip to content

Instantly share code, notes, and snippets.

@notae
Created July 20, 2014 16:36
Show Gist options
  • Save notae/c1d26557946804d743a2 to your computer and use it in GitHub Desktop.
Save notae/c1d26557946804d743a2 to your computer and use it in GitHub Desktop.
ST Monad Example
-- ST Monad Example
import Control.Monad.ST (ST)
import Control.Monad.ST (runST)
import Data.STRef (STRef)
import Data.STRef (modifySTRef)
import Data.STRef (newSTRef)
import Data.STRef (readSTRef)
prog :: Int -> ST s Int
prog i = do
r <- newSTRef i
modifySTRef r (+ 2)
modifySTRef r (* 3)
readSTRef r
test :: Int -> Int
test i = runST (prog i)
-- export error
prog2 :: Int -> ST s (STRef s Int)
prog2 i = do
newSTRef i
-- test2 :: Int -> STRef s Int
-- test2 i = runST (prog2 i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment