nikita-volkov/typeclasses/1.0.0

NOTE: the latest version is 1.8.0

Typeclasses.Classes.Comparison

Comparison typeclass definition and its instances for basic types.

Definition

type alias Comparison a =
{ equality : Equality a
, compare : a -> a -> Order
, lt : a -> a -> Bool
, le : a -> a -> Bool
, gt : a -> a -> Bool
, ge : a -> a -> Bool
, min : a -> a -> a
, max : a -> a -> a
}

Explicit typeclass which implements comparison operations for type a.

Construction utilities

compare : (a -> a -> Order) -> Comparison a

Construct an instance from just a compare function.

equalityAndLt : Equality a -> (a -> a -> Bool) -> Comparison a

Construct an instance from an instance of equality and a lesser-than function.

comparable : Comparison comparable

Construct an instance for a comparable type using the compiler-generated definitions.

Instance transformation utilities

map : (a -> b) -> (b -> a) -> Comparison a -> Comparison b

Map over the owner type of an instance to produce a new instance.

You need to provide both a covariant and a contravariant mapping (i.e., (a -> b) and (b -> a)).

Instances

int : Comparison Int

Instance for Int.

float : Comparison Float

Instance for Float.