packages feed

monadio-unwrappable 0.1 → 0.2

raw patch · 3 files changed

+29/−12 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Control.Monad.IO.Unwrappable: instance (Error e, MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (ErrorT e m) (EitherChain c e) s
- Control.Monad.IO.Unwrappable: instance (MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (ReaderT r m) c (r, s)
- Control.Monad.IO.Unwrappable: instance (MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (StateT r m) c (IORef r, s)
- Control.Monad.IO.Unwrappable: instance MonadIOUnwrappable IO Single ()
+ Control.Monad.IO.Unwrappable: instance (Error e, MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (ErrorT e m)
+ Control.Monad.IO.Unwrappable: instance (MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (ReaderT r m)
+ Control.Monad.IO.Unwrappable: instance (MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (StateT r m)
+ Control.Monad.IO.Unwrappable: instance MonadIOUnwrappable IO
- Control.Monad.IO.MonadIOException: bracketIO :: MonadIOUnwrappable m d e => IO a -> (a -> IO b) -> (a -> m c) -> m c
+ Control.Monad.IO.MonadIOException: bracketIO :: MonadIOUnwrappable m => IO a -> (a -> IO b) -> (a -> m c) -> m c
- Control.Monad.IO.Unwrappable: class MonadIO m => MonadIOUnwrappable m c s | m -> c, m -> s
+ Control.Monad.IO.Unwrappable: class MonadIO m => MonadIOUnwrappable m
- Control.Monad.IO.Unwrappable: rewrapMonadIO :: MonadIOUnwrappable m c s => s -> c a -> m a
+ Control.Monad.IO.Unwrappable: rewrapMonadIO :: MonadIOUnwrappable m => MonadIOStateType m -> MonadIOWrapType m a -> m a
- Control.Monad.IO.Unwrappable: unwrapMonadIO :: MonadIOUnwrappable m c s => s -> m a -> IO (c a)
+ Control.Monad.IO.Unwrappable: unwrapMonadIO :: MonadIOUnwrappable m => MonadIOStateType m -> m a -> IO (MonadIOWrapType m a)
- Control.Monad.IO.Unwrappable: unwrapState :: MonadIOUnwrappable m c s => m s
+ Control.Monad.IO.Unwrappable: unwrapState :: MonadIOUnwrappable m => m (MonadIOStateType m)

Files

Control/Monad/IO/MonadIOException.hs view
@@ -4,7 +4,13 @@ import Control.Monad.IO.Class import Control.Exception -bracketIO :: MonadIOUnwrappable m d e => IO a -> (a -> IO b) -> (a -> m c) -> m c+-- | Guarantees that an IO operation will be performed before an after executing+-- | a MonadIOUnwrappable monad. The operation will be performed even if the+-- | MonadIO contains error monads that fails, or if an exception is raised.+bracketIO :: MonadIOUnwrappable m => IO a           -- ^ The operation to perform initially.+                                     -> (a -> IO b) -- ^ The cleanup that should always be performed +                                     -> (a -> m c)  -- ^ The monad transformer stack to execute.+                                     -> m c bracketIO init cleanup action = do   s <- unwrapState   r <- liftIO $ bracket init cleanup (\x -> unwrapMonadIO s (action x))
Control/Monad/IO/Unwrappable.hs view
@@ -1,5 +1,6 @@-{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances #-}--- | Code in this module is not directly related to CellML, but it is rather convenience code used by the solver.+{-# LANGUAGE TypeFamilies #-}+-- | Contains a class and instance for MonadIO implementations that can be run directly in MonadIO and+-- | then reconstructed to the original type, without changing the overall semantics. module Control.Monad.IO.Unwrappable (MonadIOUnwrappable, unwrapState, unwrapMonadIO, rewrapMonadIO) where        @@ -17,35 +18,45 @@  -- | Represents a MonadIO where any change further up the monad stack can be -- | represented lower down in the stack.-class MonadIO m => MonadIOUnwrappable m c s | m -> c, m -> s where+class MonadIO m => MonadIOUnwrappable m where+  type MonadIOWrapType m :: * -> *+  type MonadIOStateType m :: *   -- | Sets up state (e.g. an IORef) to be used to simulate the monad from the   -- | IO monad.-  unwrapState :: m s+  unwrapState :: m (MonadIOStateType m)      -- | Maps the monad to only use IO level constructs and the state set up    -- | using unwrapState.-  unwrapMonadIO :: s -> m a -> IO (c a)+  unwrapMonadIO :: MonadIOStateType m -> m a -> IO (MonadIOWrapType m a)      -- | Reverses a previous unwrapMonadIO operation.-  rewrapMonadIO :: s -> c a -> m a+  rewrapMonadIO :: MonadIOStateType m -> MonadIOWrapType m a -> m a -instance MonadIOUnwrappable IO Single () where+instance MonadIOUnwrappable IO where+  type MonadIOWrapType IO = Single+  type MonadIOStateType IO = ()   unwrapState = return ()   unwrapMonadIO _ asIO = liftM Single asIO   rewrapMonadIO _ (Single x) = return x  newtype EitherChain a b c = EitherChain (a (Either b c))-instance (Error e, MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (ErrorT e m) (EitherChain c e) s where+instance (Error e, MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (ErrorT e m) where+  type MonadIOWrapType (ErrorT e m) = EitherChain (MonadIOWrapType m) e+  type MonadIOStateType (ErrorT e m) = MonadIOStateType m   unwrapState = lift (unwrapState)   unwrapMonadIO s m = liftM EitherChain $ unwrapMonadIO s (runErrorT m)   rewrapMonadIO s (EitherChain v) = ErrorT (rewrapMonadIO s v) -instance (MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (ReaderT r m) c (r, s) where+instance (MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (ReaderT r m) where+  type MonadIOWrapType (ReaderT r m) = MonadIOWrapType m+  type MonadIOStateType (ReaderT r m) = (r, MonadIOStateType m)   unwrapState = liftM2 (,) ask (lift unwrapState)   unwrapMonadIO (r, s) m = unwrapMonadIO s (runReaderT m r)   rewrapMonadIO (_, s) v = ReaderT (\_ -> rewrapMonadIO s v) -instance (MonadIO m, MonadIOUnwrappable m c s) => MonadIOUnwrappable (StateT r m) c (IORef r, s) where+instance (MonadIO m, MonadIOUnwrappable m) => MonadIOUnwrappable (StateT r m) where+  type MonadIOWrapType (StateT r m) = MonadIOWrapType m+  type MonadIOStateType (StateT r m) = (IORef r, MonadIOStateType m)   unwrapState = liftM2 (,) (get >>= (liftIO . newIORef)) (lift unwrapState)   unwrapMonadIO (r, s) m = unwrapMonadIO s $ do     s0 <- liftIO (readIORef r)
monadio-unwrappable.cabal view
@@ -1,5 +1,5 @@ Name: monadio-unwrappable-Version: 0.1+Version: 0.2 Cabal-Version: >= 1.6 Build-Type: Simple License: BSD3