packages feed

collect-errors 0.1.5.0 → 0.1.6.0

raw patch · 4 files changed

+65/−40 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Numeric.CollectErrors: unCNfn1 :: (a -> CN p) -> a -> p
+ Numeric.CollectErrors: unCNfn2 :: (a -> b -> CN p) -> a -> b -> p
+ Numeric.CollectErrors.Type: unCNfn1 :: (a -> CN p) -> a -> p
+ Numeric.CollectErrors.Type: unCNfn2 :: (a -> b -> CN p) -> a -> b -> p

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for collect-errors +## v0.1.6++* Add utilities unCNfn1, unCNfn2+ ## v0.1.5  * Make clearPotentialErrors generic, with instances for CN, pairs and lists
collect-errors.cabal view
@@ -1,13 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack------ hash: 8eba751f00934a634ce2f4c449b32d985bc3bc82cd2c36b0b83929848a47cb0a  name:           collect-errors-version:        0.1.5.0+version:        0.1.6.0 synopsis:       Error monad with a Float instance description:    Please see the README on GitHub at <https://github.com/michalkonecny/collect-errors#readme> category:       Math@@ -15,7 +13,7 @@ bug-reports:    https://github.com/michalkonecny/collect-errors/issues author:         Michal Konecny maintainer:     mikkonecny@gmail.com-copyright:      2021 Michal Konecny+copyright:      2021, 2024 Michal Konecny license:        BSD3 license-file:   LICENSE build-type:     Simple
src/Numeric/CollectErrors.hs view
@@ -1,7 +1,7 @@ module Numeric.CollectErrors (   -- * Type of numeric errors-  NumError(..), ErrorCertaintyLevel(..), NumErrors, CN, cn, unCN, (~!)+  NumError(..), ErrorCertaintyLevel(..), NumErrors, CN, cn, unCN, unCNfn1, unCNfn2, (~!)   -- * Utilities , noValueNumErrorCertain, noValueNumErrorPotential , removeValueErrorCertain, removeValueErrorPotential
src/Numeric/CollectErrors/Type.hs view
@@ -1,42 +1,64 @@-{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE ConstraintKinds #-}-module Numeric.CollectErrors.Type +{-# LANGUAGE TypeSynonymInstances #-} -where+module Numeric.CollectErrors.Type where -import GHC.Generics+import Control.CollectErrors+  ( CanTakeErrors,+    CanTestErrorsCertain (..),+    CanTestErrorsPresent,+    CollectErrors (CollectErrors),+    lift1TCE,+    lift2CE,+    liftCE,+    liftT1CE,+    noValue,+    prependErrors,+    removeValue,+    unCollectErrors,+  ) import Control.DeepSeq- import qualified Data.List as List import qualified Data.Set as Set+import GHC.Generics -import Control.CollectErrors-    ( CanTestErrorsCertain(..), CollectErrors (CollectErrors), noValue, removeValue, prependErrors, liftCE, lift2CE, lift1TCE, liftT1CE, unCollectErrors, CanTestErrorsPresent, CanTakeErrors  )+type CN = CollectErrors NumErrors  cn :: v -> CN v cn = pure +{-| Unsafe way to get a value out of the CN wrapper. -} unCN :: CN p -> p unCN = unCollectErrors -type CN = CollectErrors NumErrors+{-| Unsafe way to get the result of a function out of the CN wrapper. -}+unCNfn1 :: (a -> CN p) -> a -> p+unCNfn1 fn a = unCollectErrors (fn a)++{-| Unsafe way to get the result of a binary function out of the CN wrapper. -}+unCNfn2 :: (a -> b -> CN p) -> a -> b -> p+unCNfn2 fn a b = unCollectErrors (fn a b)+ newtype NumErrors = NumErrors (Set.Set NumErrorLevel)   deriving (Eq, Semigroup, Monoid, CanTestErrorsCertain, CanTestErrorsPresent, Generic, NFData)+ type NumErrorLevel = (NumError, ErrorCertaintyLevel)  instance Show NumErrors where   show (NumErrors set) =-    "{" <> (List.intercalate "; " $ map showEL $ Set.toList set)  <>  "}"+    "{" <> (List.intercalate "; " $ map showEL $ Set.toList set) <> "}"     where-    showEL (e,l) =-      show l <> ": " <> show e+      showEL (e, l) =+        show l <> ": " <> show e -data NumError =-    DivByZero | OutOfDomain String | NumError String-    deriving (Eq, Ord, Generic)+data NumError+  = DivByZero+  | OutOfDomain String+  | NumError String+  deriving (Eq, Ord, Generic)  instance NFData NumError @@ -45,8 +67,9 @@   show (OutOfDomain s) = "out of domain: " ++ s   show (NumError s) = "numeric error: " ++ s -data ErrorCertaintyLevel =-  ErrorCertain | ErrorPotential+data ErrorCertaintyLevel+  = ErrorCertain+  | ErrorPotential   deriving (Eq, Ord, Generic)  instance NFData ErrorCertaintyLevel@@ -58,57 +81,57 @@ instance CanTestErrorsCertain NumErrorLevel where   hasCertainError = (== ErrorCertain) . snd -{-| Construct an empty wrapper indicating that given error has certainly occurred. -}+-- | Construct an empty wrapper indicating that given error has certainly occurred. noValueNumErrorCertain :: NumError -> CN v noValueNumErrorCertain e = noValue $ NumErrors $ Set.singleton (e, ErrorCertain) -{-| Construct an empty wrapper indicating that given error may have occurred. -}+-- | Construct an empty wrapper indicating that given error may have occurred. noValueNumErrorPotential :: NumError -> CN v noValueNumErrorPotential e = noValue $ NumErrors $ Set.singleton (e, ErrorPotential)  removeValueErrorCertain :: CN t -> NumError -> CN t-removeValueErrorCertain v e = +removeValueErrorCertain v e =   removeValue v $ NumErrors $ Set.singleton (e, ErrorCertain)  removeValueErrorPotential :: CN t -> NumError -> CN t-removeValueErrorPotential v e = +removeValueErrorPotential v e =   removeValue v $ NumErrors $ Set.singleton (e, ErrorPotential)  prependErrorCertain :: NumError -> CN t -> CN t prependErrorCertain e = prependErrors $ NumErrors $ Set.singleton (e, ErrorCertain)-  + prependErrorPotential :: NumError -> CN t -> CN t prependErrorPotential e = prependErrors $ NumErrors $ Set.singleton (e, ErrorPotential)  class CanClearPotentialErrors cnt where-  {-|-    If there is a value, remove any potential errors that are associated with it.-  -}+  -- |+  --    If there is a value, remove any potential errors that are associated with it.   clearPotentialErrors :: cnt -> cnt  instance CanClearPotentialErrors (CN t) where   clearPotentialErrors (CollectErrors (Just v) (NumErrors es)) =     CollectErrors (Just v) (NumErrors $ Set.filter notPotential es)     where-    notPotential (_, ErrorPotential) = False-    notPotential _ = True+      notPotential (_, ErrorPotential) = False+      notPotential _ = True   clearPotentialErrors ce = ce -instance (CanClearPotentialErrors t1, CanClearPotentialErrors t2) => CanClearPotentialErrors (t1,t2) where-  clearPotentialErrors (v1,v2) = (clearPotentialErrors v1, clearPotentialErrors v2)+instance (CanClearPotentialErrors t1, CanClearPotentialErrors t2) => CanClearPotentialErrors (t1, t2) where+  clearPotentialErrors (v1, v2) = (clearPotentialErrors v1, clearPotentialErrors v2)  instance (CanClearPotentialErrors t) => CanClearPotentialErrors [t] where   clearPotentialErrors = map clearPotentialErrors -liftCN  :: (a -> (CN c)) -> (CN a) -> (CN c)+liftCN :: (a -> (CN c)) -> (CN a) -> (CN c) liftCN = liftCE -lift2CN  :: (a -> b -> (CN c)) -> (CN a) -> (CN b) -> (CN c)+lift2CN :: (a -> b -> (CN c)) -> (CN a) -> (CN b) -> (CN c) lift2CN = lift2CE -lift1TCN  :: (a -> b -> (CN c)) -> (CN a) -> b -> (CN c)+lift1TCN :: (a -> b -> (CN c)) -> (CN a) -> b -> (CN c) lift1TCN = lift1TCE-liftT1CN  :: (a -> b -> (CN c)) -> a -> (CN b) -> (CN c)++liftT1CN :: (a -> b -> (CN c)) -> a -> (CN b) -> (CN c) liftT1CN = liftT1CE  type CanTakeCNErrors = CanTakeErrors NumErrors