From 69e0890ecdd3acfb58394f0e6f1f8b45cc564425 Mon Sep 17 00:00:00 2001 From: Michael Walker Date: Sun, 26 Feb 2017 03:17:02 +0000 Subject: [PATCH] Make Conc a MonadRef/MonadAtomicRef. Closes #72. --- dejafu/Test/DejaFu/Conc.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dejafu/Test/DejaFu/Conc.hs b/dejafu/Test/DejaFu/Conc.hs index 907e7a5..3cb1d35 100755 --- a/dejafu/Test/DejaFu/Conc.hs +++ b/dejafu/Test/DejaFu/Conc.hs @@ -50,7 +50,8 @@ import Control.Exception (MaskingState(..)) import qualified Control.Monad.Base as Ba import qualified Control.Monad.Catch as Ca import qualified Control.Monad.IO.Class as IO -import Control.Monad.Ref (MonadRef,) +import Control.Monad.Ref (MonadRef) +import qualified Control.Monad.Ref as Re import Control.Monad.ST (ST) import qualified Data.Foldable as F import Data.IORef (IORef) @@ -87,6 +88,18 @@ instance IO.MonadIO ConcIO where instance Ba.MonadBase IO ConcIO where liftBase = IO.liftIO +instance Re.MonadRef (CRef r) (Conc n r) where + newRef a = toConc (\c -> ANewCRef "" a c) + + readRef ref = toConc (AReadCRef ref) + + writeRef ref a = toConc (\c -> AWriteCRef ref a (c ())) + + modifyRef ref f = toConc (AModCRef ref (\a -> (f a, ()))) + +instance Re.MonadAtomicRef (CRef r) (Conc n r) where + atomicModifyRef ref f = toConc (AModCRef ref f) + instance Ca.MonadCatch (Conc n r) where catch ma h = toConc (ACatching (unC . h) (unC ma))