Ranged-sets-0.1.0: Ranged sets for HaskellContentsIndex
Data.Ranged.Boundaries
Portabilityportable
Stabilityexperimental
Maintainerpaul@cogito.org.uk
Description
Synopsis
class Ord a => DiscreteOrdered a where
adjacent :: a -> a -> Bool
adjacent :: DiscreteOrdered a => a -> a -> Bool
enumAdjacent :: (Ord a, Enum a) => a -> a -> Bool
boundedAdjacent :: (Ord a, Enum a) => a -> a -> Bool
data Boundary a
= BoundaryAbove a
| BoundaryBelow a
| BoundaryAboveAll
| BoundaryBelowAll
above :: Ord v => Boundary v -> v -> Bool
(/>/) :: Ord v => v -> Boundary v -> Bool
Documentation
class Ord a => DiscreteOrdered a where

Distinguish between dense and sparse ordered types. A dense type is one in which any two values v1 < v2 have a third value v3 such that v1 < v3 < v2.

In theory the floating types are dense, although in practice they can only have finitely many values. This class treats them as dense.

Tuples up to 4 members are declared as instances. Larger tuples may be added if necessary.

This approach was suggested by Ben Rudiak-Gould on comp.lang.functional.

Methods
adjacent :: a -> a -> Bool
Two values x and y are adjacent if x < y and there does not exist a third value between them. Always False for dense types.
show/hide Instances
adjacent :: DiscreteOrdered a => a -> a -> Bool
Two values x and y are adjacent if x < y and there does not exist a third value between them. Always False for dense types.
enumAdjacent :: (Ord a, Enum a) => a -> a -> Bool
Check adjacency for sparse enumerated types (i.e. where there is no value between x and succ x). Use as the definition of adjacent for most enumerated types.
boundedAdjacent :: (Ord a, Enum a) => a -> a -> Bool
Check adjacency, allowing for case where x = maxBound. Use as the definition of adjacent for bounded enumerated types such as Int and Char.
data Boundary a

A Boundary is a division of an ordered type into values above and below the boundary. No value can sit on a boundary.

Known bug: for Bounded types

  • BoundaryAbove maxBound < BoundaryAboveAll
  • BoundaryBelow minBound > BoundaryBelowAll

This is incorrect because there are no possible values in between the left and right sides of these inequalities.

Constructors
BoundaryAbove aThe argument is the highest value below the boundary.
BoundaryBelow aThe argument is the lowest value above the boundary.
BoundaryAboveAllThe boundary above all values.
BoundaryBelowAllThe boundary below all values.
show/hide Instances
Arbitrary a => Arbitrary (Boundary a)
DiscreteOrdered a => Eq (Boundary a)
DiscreteOrdered a => Ord (Boundary a)
Show a => Show (Boundary a)
above :: Ord v => Boundary v -> v -> Bool
True if the value is above the boundary, false otherwise.
(/>/) :: Ord v => v -> Boundary v -> Bool
Same as above, but with the arguments reversed for more intuitive infix usage.
Produced by Haddock version 0.8