provide Control.Monad.ST.pureST
Allows contained mutation within a pure interface
commit6d0302229140c866a36ee8eb6a9a03ab0f0bbb96
authorKevin Mahoney <kevin@kevinmahoney.co.uk>
dateSat 29 Nov 2014, 14:02 (12 years ago)
parentbcabaab
examples/failing/Eff.pursnew file+12
@@ -0,0 +1,12 @@
1+module Main where
2+
3+import Prelude
4+import Control.Monad.Eff
5+import Control.Monad.ST
6+import Debug.Trace
7+
8+test = pureST (do
9+ ref <- newSTRef 0
10+ trace "ST"
11+ modifySTRef ref $ \n -> n + 1
12+ readSTRef ref)
examples/passing/Eff.purs+6
@@ -14,6 +14,12 @@ test2 = runPure (runST (do
1414 modifySTRef ref $ \n -> n + 1
1515 readSTRef ref))
1616
17+test3 = pureST (do
18+ ref <- newSTRef 0
19+ modifySTRef ref $ \n -> n + 1
20+ readSTRef ref)
21+
1722main = do
1823 test1
1924 Debug.Trace.print test2
25+ Debug.Trace.print test3
prelude/README.md+2
@@ -371,6 +371,8 @@
371371
372372 runST :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
373373
374+ pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
375+
374376 runSTArray :: forall a r. (forall h. Eff (st :: ST h | r) (STArray h a)) -> Eff r [a]
375377
376378 writeSTRef :: forall a h r. STRef h a -> a -> Eff (st :: ST h | r) a
prelude/prelude.purs+2
@@ -915,3 +915,5 @@ module Control.Monad.ST where
915915 \ return f;\
916916 \}" :: forall a r. (forall h. Eff (st :: ST h | r) a) -> Eff r a
917917
918+ pureST :: forall a. (forall h r. Eff (st :: ST h | r) a) -> a
919+ pureST st = runPure (runST st)