altfloat-0.2.1: Alternative floating point support for GHC.

Data.Poset

Description

Partially ordered data types. The standard Ord class is for total orders and therefore not suitable for floating point. However, we can still define meaningful max and sort functions for these types.

We define our own Ord class which is intended as a replacement for Ord. However, in order to take advantage of existing libraries which use Ord, we make every instance of Ord an instance of Ord. This is done using the OverlappingInstances and UndecidableInstances extensions -- it remains to be seen if problems occur as a result of this.

Synopsis

Documentation

class Eq a => Poset a whereSource

Class for partially ordered data types. Instances should satisfy the following laws for all values a, b and c:

  • a <= a.
  • a <= b and b <= a implies a == b.
  • a <= b and b <= c implies a <= c.

But note that the floating point instances don't satisfy the first rule.

Minimal complete definition: compare or <=.

Methods

compare :: a -> a -> OrderingSource

(<==>) :: a -> a -> BoolSource

Is comparable to.

(</=>) :: a -> a -> BoolSource

Is not comparable to.

(<) :: a -> a -> BoolSource

(<=) :: a -> a -> BoolSource

(>=) :: a -> a -> BoolSource

(>) :: a -> a -> BoolSource

class Poset a => Sortable a whereSource

Class for partially ordered data types where sorting makes sense. This includes all totally ordered sets and floating point types. Instances should satisfy the following laws:

  • The set of elements for which isOrdered returns true is totally ordered.
  • The max (or min) of an insignificant element and a significant element is the significant one.
  • The result of sorting a list should contain only significant elements.
  • max a b = max b a
  • min a b = min b a

The idea comes from floating point types, where non-comparable elements (NaNs) are the exception rather than the rule. For these types, we can define max, min and sortBy to ignore insignificant elements. Thus, a sort of floating point values will discard all NaNs and order the remaining elements.

Minimal complete definition: isOrdered

Methods

sortBy :: (a -> a -> Ordering) -> [a] -> [a]Source

isOrdered :: a -> BoolSource

max :: a -> a -> aSource

min :: a -> a -> aSource

class Sortable a => Ord a Source

Class for totally ordered data types. Instances should satisfy isOrdered a = True for all a.

sort :: Sortable a => [a] -> [a]Source

Sort a list using the default comparison function.

comparing :: Poset b => (a -> b) -> a -> a -> OrderingSource

Apply a function to values before comparing.