Data.Ranged.Boundaries

Ranged-sets-0.3.0: Ranged sets for Haskell

Copyright | (c) Paul Johnson 2006
License | BSD-style
Maintainer | paul@cogito.org.uk
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.Ranged.Boundaries

Description

Synopsis

- class Ord a => DiscreteOrdered a where
- enumAdjacent :: (Ord a, Enum a) => a -> a -> Bool
- boundedAdjacent :: (Ord a, Enum a) => a -> a -> Bool
- boundedBelow :: (Eq a, Enum a, Bounded a) => a -> Maybe a
- 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.

Most values of sparse types have an `adjacentBelow`, such that, for all x:

    case adjacentBelow x of
       Just x1 -> adjacent x1 x
       Nothing -> True

The exception is for bounded types when `x == lowerBound`. For dense types `adjacentBelow` always returns `Nothing`.

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

Minimal complete definition

adjacent, adjacentBelow

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.

adjacentBelow :: a -> Maybe a #

The value immediately below the argument, if it can be determined.

Instances

DiscreteOrdered Bool # |
Methods adjacent :: Bool -> Bool -> Bool # adjacentBelow :: Bool -> Maybe Bool #
DiscreteOrdered Char # |
Methods adjacent :: Char -> Char -> Bool # adjacentBelow :: Char -> Maybe Char #
DiscreteOrdered Double # |
Methods adjacent :: Double -> Double -> Bool # adjacentBelow :: Double -> Maybe Double #
DiscreteOrdered Float # |
Methods adjacent :: Float -> Float -> Bool # adjacentBelow :: Float -> Maybe Float #
DiscreteOrdered Int # |
Methods adjacent :: Int -> Int -> Bool # adjacentBelow :: Int -> Maybe Int #
DiscreteOrdered Integer # |
Methods adjacent :: Integer -> Integer -> Bool # adjacentBelow :: Integer -> Maybe Integer #
DiscreteOrdered Ordering # |
Methods adjacent :: Ordering -> Ordering -> Bool # adjacentBelow :: Ordering -> Maybe Ordering #
Ord a => DiscreteOrdered [a] # |
Methods adjacent :: [a] -> [a] -> Bool # adjacentBelow :: [a] -> Maybe [a] #
Integral a => DiscreteOrdered (Ratio a) # |
Methods adjacent :: Ratio a -> Ratio a -> Bool # adjacentBelow :: Ratio a -> Maybe (Ratio a) #
(Ord a, DiscreteOrdered b) => DiscreteOrdered (a, b) # |
Methods adjacent :: (a, b) -> (a, b) -> Bool # adjacentBelow :: (a, b) -> Maybe (a, b) #
(Ord a, Ord b, DiscreteOrdered c) => DiscreteOrdered (a, b, c) # |
Methods adjacent :: (a, b, c) -> (a, b, c) -> Bool # adjacentBelow :: (a, b, c) -> Maybe (a, b, c) #
(Ord a, Ord b, Ord c, DiscreteOrdered d) => DiscreteOrdered (a, b, c, d) # |
Methods adjacent :: (a, b, c, d) -> (a, b, c, d) -> Bool # adjacentBelow :: (a, b, c, d) -> Maybe (a, b, c, d) #

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`).

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.

boundedBelow :: (Eq a, Enum a, Bounded a) => a -> Maybe a #

The usual implementation of `adjacentBelow` for bounded enumerated types.

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 a | The argument is the highest value below the boundary.
BoundaryBelow a | The argument is the lowest value above the boundary.
BoundaryAboveAll | The boundary above all values.
BoundaryBelowAll | The boundary below all values.

Instances

DiscreteOrdered a => Eq (Boundary a) # |
Methods (==) :: Boundary a -> Boundary a -> Bool # (/=) :: Boundary a -> Boundary a -> Bool #
DiscreteOrdered a => Ord (Boundary a) # |
Methods compare :: Boundary a -> Boundary a -> Ordering # (<) :: Boundary a -> Boundary a -> Bool # (<=) :: Boundary a -> Boundary a -> Bool # (>) :: Boundary a -> Boundary a -> Bool # (>=) :: Boundary a -> Boundary a -> Bool # max :: Boundary a -> Boundary a -> Boundary a # min :: Boundary a -> Boundary a -> Boundary a #
Show a => Show (Boundary a) # |
Methods showsPrec :: Int -> Boundary a -> ShowS # show :: Boundary a -> String # showList :: [Boundary a] -> ShowS #
Arbitrary a => Arbitrary (Boundary a) # |
Methods arbitrary :: Gen (Boundary a) # shrink :: Boundary a -> [Boundary a] #
CoArbitrary a => CoArbitrary (Boundary a) # |
Methods coarbitrary :: Boundary a -> Gen b -> Gen b #

above :: Ord v => Boundary v -> v -> Bool #

True if the value is above the boundary, false otherwise.

(/>/) :: Ord v => v -> Boundary v -> Bool infix 4 #

Same as `above`, but with the arguments reversed for more intuitive infix usage.