Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dependencies": {
"purescript-prelude": "^4.0.0",
"purescript-tailrec": "^4.0.0",
"purescript-partial": "^2.0.0"
"purescript-partial": "^2.0.0",
"purescript-unsafe-coerce": "^4.0.0"
},
"devDependencies": {
"purescript-console": "^4.0.0"
Expand Down
17 changes: 17 additions & 0 deletions src/Control/Monad/ST/Class.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Control.Monad.ST.Class where

import Prelude

import Control.Monad.ST (ST)
import Control.Monad.ST.Global (Global)
import Control.Monad.ST.Global as Global
import Effect (Effect)

class MonadST s m | m -> s where
liftST :: ST s ~> m

instance monadSTEffect :: MonadST Global Effect where
liftST = Global.toEffect

instance monadSTST :: MonadST s (ST s) where
liftST = identity
18 changes: 18 additions & 0 deletions src/Control/Monad/ST/Global.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Control.Monad.ST.Global
( Global
, toEffect
) where

import Prelude

import Control.Monad.ST (ST, kind Region)
import Effect (Effect)
import Unsafe.Coerce (unsafeCoerce)

-- | This region allows `ST` computations to be converted into `Effect`
-- | computations so they can be run in a global context.
foreign import data Global :: Region

-- | Converts an `ST` computation into an `Effect` computation.
toEffect :: ST Global ~> Effect
toEffect = unsafeCoerce