module FayRef (FayRef, newFayRef, readFayRef, writeFayRef, modifyFayRef,
modifyFayRef') where
import Prelude
import FFI
data FayRef a = FayRef
newFayRef :: a -> Fay (FayRef a)
newFayRef = ffi "{contents: %1}"
readFayRef :: FayRef a -> Fay a
readFayRef = ffi "%1['contents']"
writeFayRef :: FayRef a -> a -> Fay ()
writeFayRef = ffi "%1['contents']=%2"
modifyFayRef :: FayRef a -> (a -> a) -> Fay ()
modifyFayRef ref f = readFayRef ref >>= (writeFayRef ref . f)
modifyFayRef' :: FayRef a -> (a -> a) -> Fay ()
modifyFayRef' ref f = do
x <- readFayRef ref
let x' = f x
writeFayRef ref $! x'