rio-orphans-0.1.1.0/src/0000755000000000000000000000000013251726654013100 5ustar0000000000000000rio-orphans-0.1.1.0/src/RIO/0000755000000000000000000000000013301602530013507 5ustar0000000000000000rio-orphans-0.1.1.0/test/0000755000000000000000000000000013253417303013256 5ustar0000000000000000rio-orphans-0.1.1.0/test/RIO/0000755000000000000000000000000013253726161013714 5ustar0000000000000000rio-orphans-0.1.1.0/src/RIO/Orphans.hs0000644000000000000000000000571513301602530015465 0ustar0000000000000000{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE ImplicitParams #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -- | Orphan instances for the 'RIO' data type. module RIO.Orphans ( HasResourceMap (..) , ResourceMap , withResourceMap ) where import RIO import Control.Monad.Catch (MonadCatch, MonadMask) import Control.Monad.Base (MonadBase) import Control.Monad.Trans.Resource.Internal (MonadResource (..), ReleaseMap, ResourceT (..)) import Control.Monad.Trans.Resource (runResourceT) import Control.Monad.Trans.Control (MonadBaseControl (..)) import qualified Control.Monad.Logger as LegacyLogger import Control.Monad.Logger (MonadLogger (..), LogStr) import System.Log.FastLogger (fromLogStr) import qualified GHC.Stack as GS -- | @since 0.1.0.0 deriving instance MonadCatch (RIO env) -- | @since 0.1.0.0 deriving instance MonadMask (RIO env) -- | @since 0.1.0.0 deriving instance MonadBase IO (RIO env) -- | @since 0.1.0.0 instance MonadBaseControl IO (RIO env) where type StM (RIO env) a = a liftBaseWith = withRunInIO restoreM = return -- | @since 0.1.1.0 instance Display LogStr where display = displayBytesUtf8 . fromLogStr -- | @since 0.1.1.0 instance HasLogFunc env => MonadLogger (RIO env) where monadLoggerLog loc source level msg = let ?callStack = GS.fromCallSiteList [("", GS.SrcLoc { GS.srcLocPackage = LegacyLogger.loc_package loc , GS.srcLocModule = LegacyLogger.loc_module loc , GS.srcLocFile = LegacyLogger.loc_filename loc , GS.srcLocStartLine = fst $ LegacyLogger.loc_start loc , GS.srcLocStartCol = snd $ LegacyLogger.loc_start loc , GS.srcLocEndLine = fst $ LegacyLogger.loc_end loc , GS.srcLocEndCol = snd $ LegacyLogger.loc_end loc })] in logGeneric source rioLogLevel (display $ LegacyLogger.toLogStr msg) where rioLogLevel = case level of LegacyLogger.LevelDebug -> LevelDebug LegacyLogger.LevelInfo -> LevelInfo LegacyLogger.LevelWarn -> LevelWarn LegacyLogger.LevelError -> LevelError LegacyLogger.LevelOther name -> LevelOther name -- | A collection of all of the registered resource cleanup actions. -- -- @since 0.1.0.0 type ResourceMap = IORef ReleaseMap -- | Perform an action with a 'ResourceMap' -- -- @since 0.1.0.0 withResourceMap :: MonadUnliftIO m => (ResourceMap -> m a) -> m a withResourceMap inner = withRunInIO $ \run -> runResourceT $ ResourceT $ run . inner -- | An environment with a 'ResourceMap' -- -- @since 0.1.0.0 class HasResourceMap env where resourceMapL :: Lens' env ResourceMap instance HasResourceMap (IORef ReleaseMap) where resourceMapL = id instance HasResourceMap env => MonadResource (RIO env) where liftResourceT (ResourceT f) = view resourceMapL >>= liftIO . f rio-orphans-0.1.1.0/test/Spec.hs0000644000000000000000000000005413253417303014503 0ustar0000000000000000{-# OPTIONS_GHC -F -pgmF hspec-discover #-} rio-orphans-0.1.1.0/test/RIO/OrphansSpec.hs0000644000000000000000000000141313253726161016474 0ustar0000000000000000{-# LANGUAGE NoImplicitPrelude #-} module RIO.OrphansSpec (spec) where import Test.Hspec import RIO import RIO.Orphans import Control.Monad.Trans.Resource spec :: Spec spec = do it "success" $ do ref <- newIORef False withResourceMap $ \rm -> runRIO rm $ do void $ register $ writeIORef ref True readIORef ref `shouldReturn` True it "exceptions" $ do ref <- newIORef False void $ tryAny $ withResourceMap $ \rm -> runRIO rm $ do void $ register $ writeIORef ref True throwString "ignored" readIORef ref `shouldReturn` True it "no release" $ do ref <- newIORef False void $ tryAny $ withResourceMap $ \rm -> runRIO rm $ do () <- throwString "ignored" writeIORef ref True readIORef ref `shouldReturn` False rio-orphans-0.1.1.0/LICENSE0000644000000000000000000000204313253417303013303 0ustar0000000000000000Copyright (c) 2018 Michael Snoyman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rio-orphans-0.1.1.0/Setup.hs0000644000000000000000000000005613253417303013734 0ustar0000000000000000import Distribution.Simple main = defaultMain rio-orphans-0.1.1.0/rio-orphans.cabal0000644000000000000000000000311413301523327015521 0ustar0000000000000000-- This file has been generated from package.yaml by hpack version 0.28.2. -- -- see: https://github.com/sol/hpack -- -- hash: 77de0e86872a5e0ec50e213804741ac79e8f08b768bec53e0d190ae09cc14b40 name: rio-orphans version: 0.1.1.0 synopsis: Orphan instances for the RIO type in the rio package description: See README and Haddocks at category: Control homepage: https://github.com/commercialhaskell/rio#readme bug-reports: https://github.com/commercialhaskell/rio/issues author: Michael Snoyman maintainer: michael@snoyman.com license: MIT license-file: LICENSE build-type: Simple cabal-version: >= 1.10 extra-source-files: ChangeLog.md README.md source-repository head type: git location: https://github.com/commercialhaskell/rio library exposed-modules: RIO.Orphans other-modules: Paths_rio_orphans hs-source-dirs: src build-depends: base >=4.9 && <10 , exceptions , fast-logger , monad-control , monad-logger , resourcet , rio , transformers-base default-language: Haskell2010 test-suite rio-orphans-test type: exitcode-stdio-1.0 main-is: Spec.hs other-modules: RIO.OrphansSpec Paths_rio_orphans hs-source-dirs: test ghc-options: -threaded -rtsopts -with-rtsopts=-N build-depends: base >=4.9 && <10 , exceptions , fast-logger , hspec , monad-control , monad-logger , resourcet , rio , rio-orphans , transformers-base default-language: Haskell2010 rio-orphans-0.1.1.0/ChangeLog.md0000644000000000000000000000022713301254242014444 0ustar0000000000000000# Changelog for rio-orphans ## 0.1.1.0 * Add an instance for `MonadLogger` typeclass, from the `monad-logger` library ## 0.1.0.0 * Initial release rio-orphans-0.1.1.0/README.md0000644000000000000000000000037413253417303013562 0ustar0000000000000000# rio-orphans Provides orphan instances for the `RIO` data type. Currently supports: * `MonadCatch` and `MonadMask` from `exceptions` * `MonadBase` from `transformers-base` * `MonadBaseControl` from `monad-control` * `MonadResource` from `resourcet`