summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffreyMainland <>2014-10-09 19:09:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2014-10-09 19:09:00 (GMT)
commit9aec8b495a9ae93abf81e4c583a5844ff15e44b6 (patch)
tree556c23e76c3f0142eb15fd38fc650388fff719de
parentba94e34c7d638d676b14cc8e477f14e03b71d00d (diff)
version 0.3.0.40.3.0.4
-rw-r--r--Control/Monad/Ref.hs193
-rw-r--r--LICENSE2
-rw-r--r--Setup.hs1
-rw-r--r--ref-fd.cabal10
4 files changed, 132 insertions, 74 deletions
diff --git a/Control/Monad/Ref.hs b/Control/Monad/Ref.hs
index 53160b2..b5d949e 100644
--- a/Control/Monad/Ref.hs
+++ b/Control/Monad/Ref.hs
@@ -1,19 +1,19 @@
+{-# LANGUAGE CPP #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FunctionalDependencies #-}
+{-# LANGUAGE MultiParamTypeClasses #-}
+{-# LANGUAGE UndecidableInstances #-}
+{-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
+
-- |
-- Module : Control.Monad.Ref
-- Copyright : (c) Harvard University 2006-2011
--- (c) Geoffrey Mainland 2011-2012
+-- (c) Geoffrey Mainland 2011-2014
-- License : BSD-style
--- Maintainer : mainland@eecs.harvard.edu
+-- Maintainer : Geoffrey Mainland <mainland@cs.drexel.edu>
--
-- Stability : experimental
-- Portability : non-portable
---
---------------------------------------------------------------------------------
-
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE FunctionalDependencies #-}
-{-# LANGUAGE MultiParamTypeClasses #-}
-{-# LANGUAGE UndecidableInstances #-}
module Control.Monad.Ref (
MonadRef(..),
@@ -28,6 +28,9 @@ import Control.Concurrent.STM.TVar (TVar,
import Control.Monad.ST (ST)
import Control.Monad.Trans.Cont (ContT)
import Control.Monad.Trans.Error (ErrorT, Error)
+#if MIN_VERSION_transformers(0,4,0)
+import Control.Monad.Trans.Except (ExceptT)
+#endif /* MIN_VERSION_transformers(0,4,0) */
import Control.Monad.Trans.Identity (IdentityT)
import Control.Monad.Trans.List (ListT)
import Control.Monad.Trans.Maybe (MaybeT)
@@ -38,6 +41,10 @@ import Control.Monad.Trans.Writer.Lazy as Lazy (WriterT)
import Control.Monad.Trans.Writer.Strict as Strict (WriterT)
import Control.Monad.Trans.Class (lift)
import Data.IORef (IORef,
+#if MIN_VERSION_base(4,6,0)
+ atomicModifyIORef',
+ modifyIORef',
+#endif /* MIN_VERSION_base(4,6,0) */
atomicModifyIORef,
modifyIORef,
newIORef,
@@ -45,6 +52,9 @@ import Data.IORef (IORef,
writeIORef)
import Data.Monoid (Monoid)
import Data.STRef (STRef,
+#if MIN_VERSION_base(4,6,0)
+ modifySTRef',
+#endif /* MIN_VERSION_base(4,6,0) */
modifySTRef,
newSTRef,
readSTRef,
@@ -64,22 +74,39 @@ class (Monad m) => MonadRef r m | m -> r where
-- |Mutate the contents of a reference
modifyRef :: r a -> (a -> a) -> m ()
modifyRef r f = readRef r >>= writeRef r . f
+ -- |Strict version of 'modifyRef'
+ modifyRef' :: r a -> (a -> a) -> m ()
+ modifyRef' r f = readRef r >>= \x -> let x' = f x in x' `seq` writeRef r x'
class (MonadRef r m) => MonadAtomicRef r m | m -> r where
-- |Atomically mutate the contents of a reference
atomicModifyRef :: r a -> (a -> (a, b)) -> m b
+ -- |Strict version of atomicModifyRef. This forces both the value stored in
+ -- the reference as well as the value returned.
+ atomicModifyRef' :: r a -> (a -> (a, b)) -> m b
+ atomicModifyRef' r f = do
+ b <- atomicModifyRef r
+ (\x -> let (a, b) = f x
+ in (a, a `seq` b))
+ b `seq` return b
instance MonadRef (STRef s) (ST s) where
- newRef = newSTRef
- readRef = readSTRef
- writeRef = writeSTRef
- modifyRef = modifySTRef
+ newRef = newSTRef
+ readRef = readSTRef
+ writeRef = writeSTRef
+ modifyRef = modifySTRef
+#if MIN_VERSION_base(4,6,0)
+ modifyRef' = modifySTRef'
+#endif /* MIN_VERSION_base(4,6,0) */
instance MonadRef IORef IO where
- newRef = newIORef
- readRef = readIORef
- writeRef = writeIORef
- modifyRef = modifyIORef
+ newRef = newIORef
+ readRef = readIORef
+ writeRef = writeIORef
+ modifyRef = modifyIORef
+#if MIN_VERSION_base(4,6,0)
+ modifyRef' = modifyIORef'
+#endif /* MIN_VERSION_base(4,6,0) */
instance MonadRef TVar STM where
newRef = newTVar
@@ -87,67 +114,89 @@ instance MonadRef TVar STM where
writeRef = writeTVar
instance MonadRef r m => MonadRef r (ContT r' m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance (Error e, MonadRef r m) => MonadRef r (ErrorT e m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
+
+#if MIN_VERSION_transformers(0,4,0)
+instance (MonadRef r m) => MonadRef r (ExceptT e m) where
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
+#endif /* MIN_VERSION_transformers(0,4,0) */
instance MonadRef r m => MonadRef r (IdentityT m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadRef r m => MonadRef r (ListT m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadRef r m => MonadRef r (MaybeT m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadRef r m => MonadRef r (ReaderT r' m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadRef r m => MonadRef r (Lazy.StateT s m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadRef r m => MonadRef r (Strict.StateT s m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance (Monoid w, MonadRef r m) => MonadRef r (Lazy.WriterT w m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance (Monoid w, MonadRef r m) => MonadRef r (Strict.WriterT w m) where
- newRef r = lift $ newRef r
- readRef r = lift $ readRef r
- writeRef r x = lift $ writeRef r x
- modifyRef r f = lift $ modifyRef r f
+ newRef r = lift $ newRef r
+ readRef r = lift $ readRef r
+ writeRef r x = lift $ writeRef r x
+ modifyRef r f = lift $ modifyRef r f
+ modifyRef' r f = lift $ modifyRef' r f
instance MonadAtomicRef IORef IO where
atomicModifyRef = atomicModifyIORef
+#if MIN_VERSION_base(4,6,0)
+ atomicModifyRef' = atomicModifyIORef'
+#endif /* MIN_VERSION_base(4,6,0) */
instance MonadAtomicRef TVar STM where
atomicModifyRef r f = do x <- readRef r
@@ -156,31 +205,41 @@ instance MonadAtomicRef TVar STM where
return y
instance MonadAtomicRef r m => MonadAtomicRef r (ContT r' m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance (Error e, MonadAtomicRef r m) => MonadAtomicRef r (ErrorT e m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (IdentityT m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (ListT m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (MaybeT m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (ReaderT r' m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (Lazy.StateT s m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance MonadAtomicRef r m => MonadAtomicRef r (Strict.StateT s m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance (Monoid w, MonadAtomicRef r m) => MonadAtomicRef r (Lazy.WriterT w m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
instance (Monoid w, MonadAtomicRef r m) => MonadAtomicRef r (Strict.WriterT w m) where
- atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef r f = lift $ atomicModifyRef r f
+ atomicModifyRef' r f = lift $ atomicModifyRef' r f
diff --git a/LICENSE b/LICENSE
index 66639af..fc28b62 100644
--- a/LICENSE
+++ b/LICENSE
@@ -25,7 +25,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
-Copyright (c) 2011-2012, Geoffrey Mainland
+Copyright (c) 2011-2014, Geoffrey Mainland
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
diff --git a/Setup.hs b/Setup.hs
index e8ef27d..9a994af 100644
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,3 +1,2 @@
import Distribution.Simple
-
main = defaultMain
diff --git a/ref-fd.cabal b/ref-fd.cabal
index d88b2f3..94b0104 100644
--- a/ref-fd.cabal
+++ b/ref-fd.cabal
@@ -1,14 +1,14 @@
name: ref-fd
-version: 0.3.0.3
+version: 0.3.0.4
cabal-version: >= 1.6
license: BSD3
license-file: LICENSE
copyright: (c) 2006-2011 Harvard University
- (c) 2011-2012 Geoffrey Mainland
-author: Geoffrey Mainland <mainland@eecs.harvard.edu>
+ (c) 2011-2014 Geoffrey Mainland
+author: Geoffrey Mainland <mainland@cs.drexel.edu>
maintainer: mainland@eecs.harvard.edu
stability: alpha
-homepage: http://www.eecs.harvard.edu/~mainland/
+homepage: http://www.cs.drexel.edu/~mainland/
category: Control
synopsis: A type class for monads with references using functional
dependencies.
@@ -25,7 +25,7 @@ library
build-depends:
base >= 4 && < 5,
stm >= 2.1 && < 2.5,
- transformers >= 0.2 && < 0.4
+ transformers >= 0.2 && < 0.5
source-repository head
type: git