File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1919 "dependencies" : {
2020 "purescript-prelude" : " ^4.0.0" ,
2121 "purescript-tailrec" : " ^4.0.0" ,
22- "purescript-partial" : " ^2.0.0"
22+ "purescript-partial" : " ^2.0.0" ,
23+ "purescript-unsafe-coerce" : " ^4.0.0"
2324 },
2425 "devDependencies" : {
2526 "purescript-console" : " ^4.0.0"
Original file line number Diff line number Diff line change 1+ module Control.Monad.ST.Class where
2+
3+ import Prelude
4+
5+ import Control.Monad.ST (ST )
6+ import Control.Monad.ST.Global (Global )
7+ import Control.Monad.ST.Global as Global
8+ import Effect (Effect )
9+
10+ class MonadST s m | m -> s where
11+ liftST :: ST s ~> m
12+
13+ instance monadSTEffect :: MonadST Global Effect where
14+ liftST = Global .toEffect
15+
16+ instance monadSTST :: MonadST s (ST s ) where
17+ liftST = identity
Original file line number Diff line number Diff line change 1+ module Control.Monad.ST.Global
2+ ( Global
3+ , toEffect
4+ ) where
5+
6+ import Prelude
7+
8+ import Control.Monad.ST (ST , kind Region )
9+ import Effect (Effect )
10+ import Unsafe.Coerce (unsafeCoerce )
11+
12+ -- | This region allows `ST` computations to be converted into `Effect`
13+ -- | computations so they can be run in a global context.
14+ foreign import data Global :: Region
15+
16+ -- | Converts an `ST` computation into an `Effect` computation.
17+ toEffect :: ST Global ~> Effect
18+ toEffect = unsafeCoerce
You can’t perform that action at this time.
0 commit comments