Name: Anonymous 2014-06-10 18:39
Show me.
for :: STRef s a -> (a -> a) -> (a -> Bool) -> (a -> ST s b) -> ST s ()
for curr iter endTest action = do
currVal <- readSTRef curr
if (endTest currVal)
then do
action currVal
modifySTRef curr iter
for curr iter endTest action
else
return ()
example = do
a <- newSTRef (0 :: Int)
b <- newSTRef (1 :: Int)
for a (+1) (<5) $ \a -> modifySTRef b (*2)
aa <- readSTRef a
bb <- readSTRef b
return (aa, bb)