packages feed

oops 0.2.0.0 → 0.2.0.1

raw patch · 3 files changed

+33/−33 lines, 3 filesdep ~base-compatdep ~doctestPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base-compat, doctest

API changes (from Hackage documentation)

- Control.Monad.Oops: hoistEither :: forall x e m a. () => MonadError (Variant e) m => CouldBeF e x => Monad m => Either x a -> m a
+ Control.Monad.Oops: hoistEither :: forall x e m a. () => MonadError (Variant e) m => e `CouldBe` x => Monad m => Either x a -> m a
- Control.Monad.Oops: onExceptionThrow :: forall x e m a. () => MonadCatch m => Exception x => MonadError (Variant e) m => CouldBeF e x => m a -> m a
+ Control.Monad.Oops: onExceptionThrow :: forall x e m a. () => MonadCatch m => Exception x => MonadError (Variant e) m => e `CouldBe` x => m a -> m a
- Control.Monad.Oops: onLeftThrow :: forall x e m a. () => MonadError (Variant e) m => CouldBeF e x => m (Either x a) -> m a
+ Control.Monad.Oops: onLeftThrow :: forall x e m a. () => MonadError (Variant e) m => e `CouldBe` x => m (Either x a) -> m a

Files

oops.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.0  name:                   oops-version:                0.2.0.0+version:                0.2.0.1 synopsis:               Combinators for handling errors of many types in a composable way description:            Combinators for handling errors of many types in a composable way. homepage:               https://www.github.com/haskell-works/oops
src/Control/Monad/Oops.hs view
@@ -2,24 +2,20 @@ {-# LANGUAGE BlockArguments         #-} {-# LANGUAGE ConstraintKinds        #-} {-# LANGUAGE DataKinds              #-}-{-# LANGUAGE EmptyCase              #-} {-# LANGUAGE FlexibleContexts       #-} {-# LANGUAGE FlexibleInstances      #-}-{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs                  #-}-{-# LANGUAGE InstanceSigs           #-} {-# LANGUAGE LambdaCase             #-} {-# LANGUAGE PolyKinds              #-} {-# LANGUAGE RankNTypes             #-} {-# LANGUAGE ScopedTypeVariables    #-}-{-# LANGUAGE StandaloneDeriving     #-} {-# LANGUAGE TypeApplications       #-} {-# LANGUAGE TypeFamilyDependencies #-} {-# LANGUAGE TypeOperators          #-} {-# LANGUAGE UndecidableInstances   #-}  module Control.Monad.Oops-  ( -- * MTL/transformer utilities+  ( -- * Catching and throwing exceptions     catchF,     catch, @@ -29,39 +25,45 @@     snatchF,     snatch, +    -- * Typeclasses to describe oops-style errors+    CouldBeF,+    CouldBe,+    CouldBeAnyOfF,+    CouldBeAnyOf,++    -- * Variant type to carry oops-style errors+    Variant,+    VariantF,++    -- * Embedding code with oops-style error handling into other code     runOops,     runOopsInExceptT,     runOopsInEither,     suspend, -+    -- * Error handling     catchOrMap,     catchAsLeft,     catchAsNothing,     catchAndExitFailure, -    hoistEither,-    hoistMaybe,--    onLeftThrow,-    onNothingThrow,+    recover,+    recoverOrVoid, +    -- * Converting error values to oops-style error handling     onLeft,     onNothing, -    recover,-    recoverOrVoid,+    onLeftThrow,+    onNothingThrow, +    hoistEither,+    hoistMaybe,++    -- * Converting exceptions to oops-style error handling     onExceptionThrow,     onException, -    CouldBeF,-    CouldBe,-    CouldBeAnyOfF,-    CouldBeAnyOf,-    Variant,-    VariantF,-   ) where  import Control.Monad.Error.Class (MonadError (..))@@ -92,7 +94,7 @@   => (f x -> ExceptT (VariantF f e') m a)   -> ExceptT (VariantF f e ) m a   -> ExceptT (VariantF f e') m a-catchF h xs = mapExceptT (>>= go) xs+catchF h = mapExceptT (>>= go)   where     go = \case       Right success -> pure (Right success)@@ -108,8 +110,7 @@   => (x -> ExceptT (Variant e') m a)   -> ExceptT (Variant e ) m a   -> ExceptT (Variant e') m a-catch h xs-  = catchF (h . runIdentity) xs+catch h = catchF (h . runIdentity)  -- | Same as 'catchF' except the error is not removed from the type. -- This is useful for writing recursive computations or computations that@@ -121,7 +122,7 @@   => (f x -> ExceptT (VariantF f e) m a)   -> ExceptT (VariantF f e) m a   -> ExceptT (VariantF f e) m a-snatchF h xs = mapExceptT (>>= go) xs+snatchF h = mapExceptT (>>= go)   where     go = \case       Right success -> pure (Right success)@@ -139,7 +140,7 @@   => (x -> ExceptT (Variant e) m a)   -> ExceptT (Variant e) m a   -> ExceptT (Variant e) m a-snatch h xs = snatchF (h . runIdentity) xs+snatch h = snatchF (h . runIdentity)  -- | Throw an error into a variant 'MonadError' context. Note that this /isn't/ -- type-changing, so this can work for any 'MonadError', rather than just@@ -209,7 +210,7 @@   => Monad m   => ExceptT (Variant (x : e)) m a   -> ExceptT (Variant e) m (Maybe a)-catchAsNothing = catchOrMap Just (pure . (const Nothing))+catchAsNothing = catchOrMap Just (pure . const Nothing)  -- | Catch the specified exception.  If that exception is caught, exit the program. catchAndExitFailure :: forall x e m a. ()@@ -222,7 +223,7 @@ -- otherwise return 'a'. hoistEither :: forall x e m a. ()   => MonadError (Variant e) m-  => CouldBeF e x+  => e `CouldBe` x   => Monad m   => Either x a   -> m a@@ -242,7 +243,7 @@ -- otherwise return 'a'. onLeftThrow :: forall x e m a. ()   => MonadError (Variant e) m-  => CouldBeF e x+  => e `CouldBe` x   => m (Either x a)   -> m a onLeftThrow f = f >>= hoistEither@@ -295,7 +296,7 @@   => CMC.MonadCatch m   => CMC.Exception x   => MonadError (Variant e) m-  => CouldBeF e x+  => e `CouldBe` x   => m a   -> m a onExceptionThrow = onException @x throw
src/Data/Variant.hs view
@@ -7,7 +7,6 @@ {-# LANGUAGE FlexibleInstances      #-} {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE GADTs                  #-}-{-# LANGUAGE InstanceSigs           #-} {-# LANGUAGE LambdaCase             #-} {-# LANGUAGE PolyKinds              #-} {-# LANGUAGE RankNTypes             #-}@@ -154,7 +153,7 @@ -- >>> variant Left Right (There (Here (Identity 3)) :: Variant '[Bool, Int]) -- Right (Here (Identity 3)) variant :: (x -> r) -> (Variant xs -> r) -> Variant (x ': xs) -> r-variant here there = variantF (here . runIdentity) there+variant here = variantF (here . runIdentity)  class CaseF (xs :: [Type]) (f :: Type -> Type) (r :: Type) (o :: Type)     | xs f r -> o, o -> f r xs where@@ -293,7 +292,7 @@   All (c ': cs) = (c, All cs)  type family Map (f :: k -> l) (xs :: [k]) = (ys :: [l]) where-  Map f (x ': xs) = f x ': (Map f xs)+  Map f (x ': xs) = f x ': Map f xs   Map f '[] = '[]  -- | As with 'CouldBeAnyOf', we can also constrain a variant to represent