Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a value with error library in Haskell?

Tags:

haskell

I am looking for a library that provides a 'value with error' (eg x ± y). But searching for "Haskell xyz Error" only gives error handling libraries.

I would expect that such a library would provide common math operations (Num, Floating) where appropriate. The use case would be to get a error estimate from a calculation based on noisy sensor readings.

Update

I did some research and the term "propagation of uncertainty" came up. I found uncertainly-haskell which I'll try out soon. Are there other packages like this?

like image 222
fho Avatar asked Oct 25 '13 20:10

fho


People also ask

How do you handle errors in Haskell?

If we identify an error, we remove it. Thus, we don't handle errors, we simply fix them. In Haskell, we have error and undefined to cause such errors and terminate execution of the program. On the other hand, an exception is something that can go wrong or that simply doesn't follow a rule but can happen.

Does Haskell have exceptions?

There are three different ways exceptions can be thrown in Haskell: Synchronously thrown: an exception is generated from IO code and thrown inside a single thread. Asynchronously thrown: an exception is thrown from one thread to another thread to cause it to terminate early.

Is either a Monad Haskell?

Strictly speaking, Either cannot be a monad, as it has kind Type -> Type -> Type ; Either String can be (and is), because it has kind Type -> Type .


2 Answers

Have a look at the intervals package.

like image 90
Tobias Brandt Avatar answered Oct 10 '22 03:10

Tobias Brandt


The Data.Eq.Approximate module seems to be a fit for getting approximate equality.

Data.Eq.Approximate

Contents Type wrappers Classes for tolerance type annotations Absolute tolerance Relative tolerance Zero tolerance Tolerance annotations using Digits The purpose of this module is to provide newtype wrapper that allows one to effectively override the equality operator of a value so that it > is approximate rather than exact. For example, the type

type ApproximateDouble = AbsolutelyApproximateValue (Digits Five) Double defines an alias for a wrapper containing Doubles such that two doubles are equal if they are equal to within five decimals of accuracy; for > example, we have that

1 == (1+10^^(-6) :: ApproximateDouble) evaluates to True. Note that we did not need to wrap the value 1+10^^(-6) since AbsolutelyApproximateValue is an instance of Num. For > convenience, Num as well as many other of the numerical classes such as Real and Floating have all been derived for the wrappers defined in > this package so that one can conveniently use the wrapped values in the same way as one would use the values themselves.

Two kinds of wrappers are provided by this package.

like image 37
Alain O'Dea Avatar answered Oct 10 '22 01:10

Alain O'Dea