altfloat-0.3.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

Instances

 Poset Bool Poset Char Poset Int Poset Int8 Poset Int16 Poset Int32 Poset Int64 Poset Integer Poset Word Poset Word8 Poset Word16 Poset Word32 Poset Word64 Poset Float Poset Double Poset a => Poset [a] Integral a => Poset (Ratio a) Poset a => Poset (Maybe a)

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

data Ordering Source

Constructors

 LT EQ GT NC

Instances

 Bounded Ordering Enum Ordering Eq Ordering Read Ordering Show Ordering Monoid Ordering

class Sortable a => Ord a Source

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

Instances

 Ord Bool Ord Char Ord Int Ord Int8 Ord Int16 Ord Int32 Ord Int64 Ord Integer Ord Word Ord Word8 Ord Word16 Ord Word32 Ord Word64 Integral a => Ord (Ratio 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.