oops 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+35/−7 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.Oops: [Here] :: f x -> VariantF f (x : xs)
+ Control.Monad.Oops: [There] :: VariantF f xs -> VariantF f (x : xs)
+ Control.Monad.Oops: class CouldBeF xs x => CouldBe (xs :: [Type]) (x :: Type)
+ Control.Monad.Oops: class CouldBeF (xs :: [k]) (x :: k)
+ Control.Monad.Oops: data VariantF (f :: k -> Type) (xs :: [k])
+ Control.Monad.Oops: snatch :: CouldBe xs x => Variant xs -> Either (Variant xs) x
+ Control.Monad.Oops: snatchF :: CouldBeF xs x => VariantF f xs -> Either (VariantF f xs) (f x)
+ Control.Monad.Oops: throw :: CouldBe xs x => x -> Variant xs
+ Control.Monad.Oops: throwF :: CouldBeF xs x => f x -> VariantF f xs
+ Control.Monad.Oops: throwNothingAsM :: forall e es m a. () => MonadError (Variant es) m => CouldBe es e => e -> Maybe a -> m a
+ Control.Monad.Oops: type Variant (xs :: [Type]) = VariantF Identity xs
+ Control.Monad.Oops: type e `CouldBeAnyOf` xs = All (Map (CouldBe e) xs)
+ Control.Monad.Oops.Classic: [Here] :: f x -> VariantF f (x : xs)
+ Control.Monad.Oops.Classic: [There] :: VariantF f xs -> VariantF f (x : xs)
+ Control.Monad.Oops.Classic: class CouldBeF xs x => CouldBe (xs :: [Type]) (x :: Type)
+ Control.Monad.Oops.Classic: class CouldBeF (xs :: [k]) (x :: k)
+ Control.Monad.Oops.Classic: data VariantF (f :: k -> Type) (xs :: [k])
+ Control.Monad.Oops.Classic: snatch :: CouldBe xs x => Variant xs -> Either (Variant xs) x
+ Control.Monad.Oops.Classic: snatchF :: CouldBeF xs x => VariantF f xs -> Either (VariantF f xs) (f x)
+ Control.Monad.Oops.Classic: throw :: CouldBe xs x => x -> Variant xs
+ Control.Monad.Oops.Classic: throwF :: CouldBeF xs x => f x -> VariantF f xs
+ Control.Monad.Oops.Classic: throwNothingAsM :: forall e es m a. () => MonadError (Variant es) m => CouldBe es e => e -> Maybe a -> m a
+ Control.Monad.Oops.Classic: type Variant (xs :: [Type]) = VariantF Identity xs
+ Control.Monad.Oops.Classic: type e `CouldBeAnyOf` xs = All (Map (CouldBe e) xs)
Files
- oops.cabal +5/−5
- src/Control/Monad/Oops.hs +21/−2
- src/Control/Monad/Oops/Classic.hs +9/−0
oops.cabal view
@@ -1,19 +1,19 @@ cabal-version: 3.0 name: oops-version: 0.1.0.0+version: 0.1.1.0 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/i-am-tom/oops+homepage: https://www.github.com/haskell-works/oops license: MIT license-file: LICENSE author: Tom Harding maintainer: tomjharding@live.co.uk-copyright: 2019 Tom Harding- 2023 John Ky+copyright: 2023 John Ky+ 2019 Tom Harding category: Data Control-tested-with: GHC == 9.4.3, GHC == 9.2.2, GHC == 9.0.2, GHC == 8.10.7+tested-with: GHC == 9.4.4, GHC == 9.2.5, GHC == 9.0.2, GHC == 8.10.7 source-repository head type: git
src/Control/Monad/Oops.hs view
@@ -36,10 +36,18 @@ throwLeftM, throwNothingM,+ throwNothingAsM, recoverM, recoverOrVoidM, + DV.CouldBeF (..),+ DV.CouldBe (..),+ DV.CouldBeAnyOfF,+ DV.CouldBeAnyOf,+ DV.Variant,+ DV.VariantF(..),+ ) where import Control.Monad.Error.Class (MonadError (..))@@ -51,7 +59,8 @@ import Data.Variant (Catch, CatchF(..), CouldBe, CouldBeF(..), Variant, VariantF, preposterous) import Data.Void (Void, absurd) -import qualified System.Exit as IO+import qualified Data.Variant as DV+import qualified System.Exit as IO -- | When working in some monadic context, using 'catch' becomes trickier. The -- intuitive behaviour is that each 'catch' shrinks the variant in the left@@ -176,7 +185,17 @@ => Monad m => Maybe a -> m a-throwNothingM = maybe (throwM ()) pure+throwNothingM = throwNothingAsM ()++-- | When the expression of type 'Maybe a' evaluates to 'Nothing', throw the specified value,+-- otherwise return 'a'.+throwNothingAsM :: forall e es m a. ()+ => MonadError (Variant es) m+ => CouldBe es e+ => e+ -> Maybe a+ -> m a+throwNothingAsM e = maybe (throwM e) pure -- | Catch the specified exception and return it instead. -- The evaluated computation must return the same type that is being caught.
src/Control/Monad/Oops/Classic.hs view
@@ -37,16 +37,25 @@ Oops.throwLeftM, Oops.throwNothingM,+ Oops.throwNothingAsM, Oops.recoverM, Oops.recoverOrVoidM, + DV.CouldBeF (..),+ DV.CouldBe (..),+ DV.CouldBeAnyOfF,+ DV.CouldBeAnyOf,+ DV.Variant,+ DV.VariantF(..),+ ) where import Control.Monad.Error.Class (MonadError (..)) import Control.Monad.Except (ExceptT(ExceptT)) import Data.Variant ( Catch, CatchF, CouldBe, Variant, VariantF ) +import qualified Data.Variant as DV import qualified Control.Monad.Oops as Oops -- | When working in some monadic context, using 'catch' becomes trickier. The