MicroHs-0.17.4.0 / tests / ST.hs
module ST(main) whereimport Control.Monad.STimport Data.STRefimport Debug.TracefacST :: forall s . Int -> ST s IntfacST n = do ri <- newSTRef 1 rr <- newSTRef 1 let loop = do i <- readSTRef ri if i > n then return () else do writeSTRef ri (i + 1) modifySTRef rr (i *) loop loop readSTRef rrfac :: Int -> Intfac n = runST (facST n)main :: IO ()main = do print (fac 10)