unliftio-core 0.1.2.0 → 0.2.0.0
raw patch · 3 files changed
+40/−39 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- ChangeLog.md +6/−0
- src/Control/Monad/IO/Unlift.hs +24/−29
- unliftio-core.cabal +10/−10
ChangeLog.md view
@@ -1,3 +1,9 @@+# ChangeLog for unliftio-core++## 0.2.0.0++* Move `askUnliftIO` out of class [#55](https://github.com/fpco/unliftio/issues/55)+ ## 0.1.2.0 * Add `wrappedWithRunInIO`.
src/Control/Monad/IO/Unlift.hs view
@@ -4,6 +4,7 @@ module Control.Monad.IO.Unlift ( MonadUnliftIO (..) , UnliftIO (..)+ , askUnliftIO , askRunInIO , withUnliftIO , toIO@@ -41,30 +42,16 @@ -- -- * @unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f@ ----- The third is a currently nameless law which ensures that the--- current context is preserved.+-- Instances of @MonadUnliftIO@ must also satisfy the idempotency law: ----- * @askUnliftIO >>= (\u -> liftIO (unliftIO u m)) = m@+-- * @askUnliftIO >>= \\u -> (liftIO . unliftIO u) m = m@ ----- If you have a name for this, please submit it in a pull request for--- great glory.+-- This law showcases two properties. First, 'askUnliftIO' doesn't change+-- the monadic context, and second, @liftIO . unliftIO u@ is equivalent to+-- @id@ IF called in the same monadic context as 'askUnliftIO'. -- -- @since 0.1.0.0 class MonadIO m => MonadUnliftIO m where- {-# MINIMAL askUnliftIO | withRunInIO #-}- -- | Capture the current monadic context, providing the ability to- -- run monadic actions in 'IO'.- --- -- See 'UnliftIO' for an explanation of why we need a helper- -- datatype here.- --- -- @since 0.1.0.0- askUnliftIO :: m (UnliftIO m)- askUnliftIO = withRunInIO (\run -> return (UnliftIO run))- {-# INLINE askUnliftIO #-}- -- Would be better, but GHC hates us- -- askUnliftIO :: m (forall a. m a -> IO a)- -- | Convenience function for capturing the monadic context and running an 'IO' -- action with a runner function. The runner function is used to run a monadic -- action @m@ in @IO@.@@ -74,15 +61,9 @@ withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b withRunInIO inner = askUnliftIO >>= \u -> liftIO (inner (unliftIO u)) instance MonadUnliftIO IO where- {-# INLINE askUnliftIO #-}- askUnliftIO = return (UnliftIO id) {-# INLINE withRunInIO #-} withRunInIO inner = inner id instance MonadUnliftIO m => MonadUnliftIO (ReaderT r m) where- {-# INLINE askUnliftIO #-}- askUnliftIO = ReaderT $ \r ->- withUnliftIO $ \u ->- return (UnliftIO (unliftIO u . flip runReaderT r)) {-# INLINE withRunInIO #-} withRunInIO inner = ReaderT $ \r ->@@ -90,15 +71,29 @@ inner (run . flip runReaderT r) instance MonadUnliftIO m => MonadUnliftIO (IdentityT m) where- {-# INLINE askUnliftIO #-}- askUnliftIO = IdentityT $- withUnliftIO $ \u ->- return (UnliftIO (unliftIO u . runIdentityT)) {-# INLINE withRunInIO #-} withRunInIO inner = IdentityT $ withRunInIO $ \run -> inner (run . runIdentityT)++-- | Capture the current monadic context, providing the ability to+-- run monadic actions in 'IO'.+--+-- See 'UnliftIO' for an explanation of why we need a helper+-- datatype here.+--+-- Prior to version 0.2.0.0 of this library, this was a method in the+-- 'MonadUnliftIO' type class. It was moved out due to+-- <https://github.com/fpco/unliftio/issues/55>.+--+-- @since 0.1.0.0+askUnliftIO :: MonadUnliftIO m => m (UnliftIO m)+askUnliftIO = withRunInIO (\run -> return (UnliftIO run))+{-# INLINE askUnliftIO #-}+-- Would be better, but GHC hates us+-- askUnliftIO :: m (forall a. m a -> IO a)+ -- | Same as 'askUnliftIO', but returns a monomorphic function -- instead of a polymorphic newtype wrapper. If you only need to apply
unliftio-core.cabal view
@@ -1,13 +1,13 @@-cabal-version: >= 1.10+cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.29.6.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: 9dda29b2ae88c7aba738c44b9efa373de55a416be845a7bf888fc8c108166fed+-- hash: 9b9f7a8193dd633099cfaf8dc393fdfd8a2a5ea77517a9ad27a80ef76c429ff0 name: unliftio-core-version: 0.1.2.0+version: 0.2.0.0 synopsis: The MonadUnliftIO typeclass for unlifting monads to IO description: Please see the documentation and README at <https://www.stackage.org/package/unliftio-core> category: Control@@ -19,17 +19,17 @@ license-file: LICENSE build-type: Simple extra-source-files:- ChangeLog.md README.md+ ChangeLog.md library- hs-source-dirs:- src- build-depends:- base >=4.5 && <4.12- , transformers >=0.2 && <0.6 exposed-modules: Control.Monad.IO.Unlift other-modules: Paths_unliftio_core+ hs-source-dirs:+ src+ build-depends:+ base >=4.5 && <4.14+ , transformers >=0.2 && <0.6 default-language: Haskell2010