on master help sign in
Add instances to JSM to make it more like IO
60b6914Hamish Mackenzie
jsaddle.cabal+1
@@ -39,6 +39,7 @@ library
39 filepath >=1.4.0.0 && <1.5,
39 filepath >=1.4.0.0 && <1.5,
40 http-types >=0.8.6 && <0.10,
40 http-types >=0.8.6 && <0.10,
41 process >=1.2.3.0 && <1.5,
41 process >=1.2.3.0 && <1.5,
42+ ref-tf >=0.4.0.1 && <0.5,
42 stm >=2.4.4 && <2.5,
43 stm >=2.4.4 && <2.5,
43 time >=1.5.0.1 && <1.7,
44 time >=1.5.0.1 && <1.7,
44 wai >=3.0.3.0 && <3.3,
45 wai >=3.0.3.0 && <3.3,
src/Language/Javascript/JSaddle/Types.hs+21
@@ -59,8 +59,12 @@ import Data.Word (Word(..))
59import GHCJS.Nullable (Nullable(..))
59import GHCJS.Nullable (Nullable(..))
60#else
60#else
61import Control.Monad.Trans.Reader (ReaderT(..))
61import Control.Monad.Trans.Reader (ReaderT(..))
62+import Control.Monad.Trans.State.Lazy (StateT(..))
63+import qualified Control.Monad.Trans.State.Strict as Strict
64+ (StateT(..))
62import Control.Monad.Trans.Class (MonadTrans(..))
65import Control.Monad.Trans.Class (MonadTrans(..))
63import Control.Monad.Fix (MonadFix)
66import Control.Monad.Fix (MonadFix)
67+import Control.Monad.Ref (MonadAtomicRef(..), MonadRef(..))
64import Control.Concurrent.STM.TVar (TVar)
68import Control.Concurrent.STM.TVar (TVar)
65import Data.Int (Int64)
69import Data.Int (Int64)
66import Data.Text (Text)
70import Data.Text (Text)
@@ -120,6 +124,23 @@ instance MonadJSM JSM where
120instance MonadJSM m => MonadJSM (ReaderT e m) where
124instance MonadJSM m => MonadJSM (ReaderT e m) where
121 liftJSM' = lift . liftJSM'
125 liftJSM' = lift . liftJSM'
122 {-# INLINE liftJSM' #-}
126 {-# INLINE liftJSM' #-}
127+
128+instance MonadJSM m => MonadJSM (StateT r m) where
129+ liftJSM' = lift . liftJSM'
130+ {-# INLINE liftJSM' #-}
131+
132+instance MonadJSM m => MonadJSM (Strict.StateT r m) where
133+ liftJSM' = lift . liftJSM'
134+ {-# INLINE liftJSM' #-}
135+
136+instance MonadRef JSM where
137+ type Ref JSM = Ref IO
138+ newRef = liftIO . newRef
139+ readRef = liftIO . readRef
140+ writeRef r = liftIO . writeRef r
141+
142+instance MonadAtomicRef JSM where
143+ atomicModifyRef r = liftIO . atomicModifyRef r
123#endif
144#endif
124
145
125-- | The 'liftJSM' is to 'JSM' what 'liftIO' is to 'IO'.
146-- | The 'liftJSM' is to 'JSM' what 'liftIO' is to 'IO'.