easytensor-2.1.1.1: Pure, type-indexed haskell vector, matrix, and tensor library.
Copyright (c) Artem Chirkin BSD3 None Haskell2010

Numeric.ProductOrd.Partial

Description

Compare product types using partial Ord instances:

• if nor $$a > b$$, nor $$b > a$$, neither, $$a = b$$, then compare a b == undefined

To remind yourself that ProductOrd is partial, you may import it qualified, e.g.

 import qualified Numeric.ProductOrd.Partial as Partial
Synopsis

# Documentation

newtype ProductOrd a Source #

Redefine Ord instance for a type which is a cartesian product -- as a partial product order.

Since vanilla Haskell Ord class is always about total order, ProductOrd instance is not particularly correct. However, it turns out to be very useful for comparing vector or tuple-like types.

The implementation of ProductOrd in this module workarounds this by using a partial compare function in an Eq instance: $\neg (a > b) \land \neg (b > a) \land \neg (a = b) \Rightarrow \mathtt{compare\ a\ b == undefined}$

Another inconsistency with the Haskell Report is the min and max functions; these are simply element-wise minimum and maximum here. Thus, these instances preserve important properties like min a b <= a && min a b <= b, but do not preserve a property that min a b == a || min a b == b.

All of this is really useful in geometry applications and for calculating things like Pareto dominance, but should be used with care. In particular, never use ProductOrd as a key to a Set or a Map!

Constructors

 ProductOrd FieldsgetProductOrd :: a

#### Instances

Instances details
Treat Incomparable as error (partial function).