unexceptionalio 0.2.0 → 0.3.0
raw patch · 2 files changed
+32/−25 lines, 2 files
Files
- UnexceptionalIO.hs +31/−24
- unexceptionalio.cabal +1/−1
UnexceptionalIO.hs view
@@ -4,10 +4,10 @@ -- -- > runEitherIO . fromIO ≡ id module UnexceptionalIO (- UnexceptionalIO, UIO,+ Unexceptional(..), fromIO,- runUnexceptionalIO,+ runUIO, runEitherIO, -- * Unsafe entry points #ifdef __GLASGOW_HASKELL__@@ -41,49 +41,56 @@ #endif -- | IO without any non-error, synchronous exceptions-newtype UnexceptionalIO a = UnexceptionalIO (IO a)---- | or, you may prefer a short name-type UIO = UnexceptionalIO+newtype UIO a = UIO (IO a) -instance Functor UnexceptionalIO where+instance Functor UIO where fmap = liftM -instance Applicative UnexceptionalIO where+instance Applicative UIO where pure = return (<*>) = ap -instance Monad UnexceptionalIO where- return = UnexceptionalIO . return- (UnexceptionalIO x) >>= f = UnexceptionalIO (x >>= runUnexceptionalIO . f)+instance Monad UIO where+ return = UIO . return+ (UIO x) >>= f = UIO (x >>= runUIO . f) fail s = error $ "UnexceptionalIO cannot fail (" ++ s ++ ")" -instance MonadFix UnexceptionalIO where- mfix f = UnexceptionalIO (mfix $ runUnexceptionalIO . f)+instance MonadFix UIO where+ mfix f = UIO (mfix $ runUIO . f) +-- | Polymorphic base without any non-error, synchronous exceptions+class Unexceptional m where+ liftUIO :: UIO a -> m a++instance Unexceptional UIO where+ liftUIO = id++instance Unexceptional IO where+ liftUIO = runUIO+ -- | Catch any non-error, synchronous exceptions in an 'IO' action-fromIO :: IO a -> UnexceptionalIO (Either SomeException a)+fromIO :: IO a -> UIO (Either SomeException a) fromIO = unsafeFromIO . syncIO --- | Re-embed 'UnexceptionalIO' into 'IO'-runUnexceptionalIO :: UnexceptionalIO a -> IO a-runUnexceptionalIO (UnexceptionalIO io) = io+-- | Re-embed 'UIO' into 'IO'+runUIO :: UIO a -> IO a+runUIO (UIO io) = io --- | Re-embed 'UnexceptionalIO' and possible exception back into 'IO'+-- | Re-embed 'UIO' and possible exception back into 'IO' #ifdef __GLASGOW_HASKELL__-runEitherIO :: (Ex.Exception e) => UnexceptionalIO (Either e a) -> IO a+runEitherIO :: (Ex.Exception e) => UIO (Either e a) -> IO a #else-runEitherIO :: UnexceptionalIO (Either SomeException a) -> IO a+runEitherIO :: UIO (Either SomeException a) -> IO a #endif-runEitherIO = either throwIO return <=< runUnexceptionalIO+runEitherIO = either throwIO return <=< runUIO #ifdef __GLASGOW_HASKELL__ -- | You promise that 'e' covers all non-error, synchronous exceptions -- thrown by this 'IO' action -- -- This function is partial if you lie-fromIO' :: (Ex.Exception e) => IO a -> UnexceptionalIO (Either e a)+fromIO' :: (Ex.Exception e) => IO a -> UIO (Either e a) fromIO' = (return . either (Left . maybePartial . Ex.fromException) Right) <=< fromIO where@@ -92,8 +99,8 @@ #endif -- | You promise there are no exceptions thrown by this 'IO' action-unsafeFromIO :: IO a -> UnexceptionalIO a-unsafeFromIO = UnexceptionalIO+unsafeFromIO :: IO a -> UIO a+unsafeFromIO = UIO -- | Catch all exceptions, except for asynchronous exceptions found in @base@ syncIO :: IO a -> IO (Either SomeException a)
unexceptionalio.cabal view
@@ -1,5 +1,5 @@ name: unexceptionalio-version: 0.2.0+version: 0.3.0 cabal-version: >=1.8 license: OtherLicense license-file: COPYING