packages feed

unliftio-core 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+52/−18 lines, 3 filesdep ~base

Dependency ranges changed: base

Files

ChangeLog.md view
@@ -1,3 +1,10 @@+## 0.1.1.0++* Doc improvements.+* Inline functions in `Control.Monad.IO.Unlift` module [#4](https://github.com/fpco/unliftio/pull/4).+* Fully polymorphic `withRunInIO` [#12](https://github.com/fpco/unliftio/pull/12).+* Move `withRunInIO` into the `MonadUnliftIO` typeclass itself[#13](https://github.com/fpco/unliftio/issues/13)+ ## 0.1.0.0 -* Initial release+* Initial release.
src/Control/Monad/IO/Unlift.hs view
@@ -1,12 +1,11 @@ {-# LANGUAGE RankNTypes #-} -- | Please see the README.md file for information on using this--- package.+-- package at <https://www.stackage.org/package/unliftio-core>. module Control.Monad.IO.Unlift   ( MonadUnliftIO (..)   , UnliftIO (..)   , askRunInIO   , withUnliftIO-  , withRunInIO   , toIO   , MonadIO (..)   ) where@@ -52,6 +51,7 @@ -- -- @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'.   --@@ -59,18 +59,45 @@   -- 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@.+  --+  -- @since 0.1.0.0+  {-# INLINE withRunInIO #-}+  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 ->+    withRunInIO $ \run ->+    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)  -- | Same ask 'askUnliftIO', but returns a monomorphic function -- instead of a polymorphic newtype wrapper. If you only need to apply@@ -78,25 +105,23 @@ -- convenient. -- -- @since 0.1.0.0+{-# INLINE askRunInIO #-} askRunInIO :: MonadUnliftIO m => m (m a -> IO a)-askRunInIO = liftM unliftIO askUnliftIO+-- withRunInIO return would be nice, but GHC 7.8.4 doesn't like it+askRunInIO = withRunInIO (\run -> (return (\ma -> run ma)))  -- | Convenience function for capturing the monadic context and running--- an 'IO' action.+-- an 'IO' action. The 'UnliftIO' newtype wrapper is rarely needed, so+-- prefer 'withRunInIO' to this function. -- -- @since 0.1.0.0+{-# INLINE withUnliftIO #-} withUnliftIO :: MonadUnliftIO m => (UnliftIO m -> IO a) -> m a withUnliftIO inner = askUnliftIO >>= liftIO . inner --- | Same as 'withUnliftIO', but uses a monomorphic function like--- 'askRunInIO'.------ @since 0.1.0.0-withRunInIO :: MonadUnliftIO m => ((m a -> IO a) -> IO b) -> m b-withRunInIO inner = askRunInIO >>= liftIO . inner- -- | Convert an action in @m@ to an action in @IO@. -- -- @since 0.1.0.0+{-# INLINE toIO #-} toIO :: MonadUnliftIO m => m a -> m (IO a) toIO m = withRunInIO $ \run -> return $ run m
unliftio-core.cabal view
@@ -1,13 +1,15 @@--- This file has been generated from package.yaml by hpack version 0.17.0.+-- This file has been generated from package.yaml by hpack version 0.21.2. -- -- see: https://github.com/sol/hpack+--+-- hash: 30994f07a9010e7816784501ed5ff3165c34026fa5dc555ebf1a70f6d6c0f1af  name:           unliftio-core-version:        0.1.0.0+version:        0.1.1.0 synopsis:       The MonadUnliftIO typeclass for unlifting monads to IO-description:    Please see the README.md file for details+description:    Please see the documentation and README at <https://www.stackage.org/package/unliftio-core> category:       Control-homepage:       https://github.com/fpco/monad-unlift/tree/master/unliftio-core#readme+homepage:       https://github.com/fpco/unliftio/tree/master/unliftio-core#readme author:         Michael Snoyman, Francesco Mazzoli maintainer:     michael@snoyman.com copyright:      2017 FP Complete@@ -24,8 +26,8 @@   hs-source-dirs:       src   build-depends:-      base >= 4.5 && < 4.11-    , transformers >= 0.2 && < 0.6+      base >=4.5 && <4.11+    , transformers >=0.2 && <0.6   exposed-modules:       Control.Monad.IO.Unlift   other-modules: