collect-errors: Error monad with a Float instance

[ bsd3, library, math ] [ Propose Tags ]

Please see the README on GitHub at https://github.com/michalkonecny/collect-errors#readme


[Skip to Readme]
Versions [RSS] [faq] 0.1.0.0, 0.1.1.0, 0.1.2.0, 0.1.3.0, 0.1.4.0, 0.1.4.1, 0.1.5.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), containers, QuickCheck (>=2.7) [details]
License BSD-3-Clause
Copyright 2021 Michal Konecny
Author Michal Konecny
Maintainer mikkonecny@gmail.com
Category Math
Home page https://github.com/michalkonecny/collect-errors#readme
Bug tracker https://github.com/michalkonecny/collect-errors/issues
Source repo head: git clone https://github.com/michalkonecny/collect-errors
Uploaded by MichalKonecny at 2021-04-29T17:41:38Z
Distributions LTSHaskell:0.1.5.0, NixOS:0.1.5.0, Stackage:0.1.5.0
Downloads 675 total (46 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2021-04-29 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for collect-errors-0.1.0.0

[back to package description]

collect-errors

CollectErrors es t is a monad wrapper around values of type t which can accommodate (a list of) (potential) errors of type es that have (maybe) occurred during the computation of a value. A value may be missing, leaving only the error(s).

The wrapper CN t is a special case of CollectErrors es t with es = NumErrors.

The CN wrapper also propagates instances of Floating, allowing us to write expressions with partial functions (ie functions that fail for some inputs) instead of branching after each application of such function:

*Numeric.CollectErrors> a = 1 :: CN Double
*Numeric.CollectErrors> (1/(a-1))+(sqrt (a-2))
{{ERROR: division by 0; ERROR: out of domain: sqrt for negative arg -1.0}}

as opposed to:

*Prelude> a = 1 :: Double
*Prelude> (1/(a-1))+(sqrt (a-2))
NaN

Dealing with the errors can be moved outside the expression:

*Numeric.CollectErrors> a = 1 :: CN Double
*Numeric.CollectErrors> toEither $ 1/(a-1)
Left {ERROR: division by 0}

*Numeric.CollectErrors> toEither $ 1/a+(sqrt a)
Right 2.0

The CN wrapper has support for potential errors so that it can be applied to a set arithmetic such as interval arithmetic.

The Floating instance cannot be used with a set arithmetic since the instance relies on true/false comparisons but a set arithmetic has only three-valued (true/false/undecided) comparisons. Package mixed-types-num provides alternative numerical type classes in which three-valued (ie Kleenean) comparisons are available.