Distribution.Types.VersionInterval

Cabal-2.4.0.1: A framework for packaging Haskell software

Safe Haskell | None
Language | Haskell2010

Distribution.Types.VersionInterval

Contents

- Version intervals
- Version intervals view

Synopsis

- data VersionIntervals
- toVersionIntervals :: VersionRange -> VersionIntervals
- fromVersionIntervals :: VersionIntervals -> VersionRange
- withinIntervals :: Version -> VersionIntervals -> Bool
- versionIntervals :: VersionIntervals -> [VersionInterval]
- mkVersionIntervals :: [VersionInterval] -> VersionIntervals
- unionVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals
- intersectVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals
- invertVersionIntervals :: VersionIntervals -> VersionIntervals
- relaxLastInterval :: VersionIntervals -> VersionIntervals
- relaxHeadInterval :: VersionIntervals -> VersionIntervals
- asVersionIntervals :: VersionRange -> [VersionInterval]
- type VersionInterval = (LowerBound, UpperBound)
- data LowerBound = LowerBound Version !Bound
- data UpperBound
  - = NoUpperBound
  - | UpperBound Version !Bound
- data Bound
  - = ExclusiveBound
  - | InclusiveBound

# Version intervals

data VersionIntervals #

A complementary representation of a `VersionRange`. Instead of a boolean version predicate it uses an increasing sequence of non-overlapping, non-empty intervals.

The key point is that this representation gives a canonical representation for the semantics of `VersionRange`s. This makes it easier to check things like whether a version range is empty, covers all versions, or requires a certain minimum or maximum version. It also makes it easy to check equality or containment. It also makes it easier to identify 'simple' version predicates for translation into foreign packaging systems that do not support complex version range expressions.

Instances

Eq VersionIntervals # |
Instance details Defined in Distribution.Types.VersionInterval Methods (==) :: VersionIntervals -> VersionIntervals -> Bool # (/=) :: VersionIntervals -> VersionIntervals -> Bool #
Show VersionIntervals # |
Instance details Defined in Distribution.Types.VersionInterval Methods showsPrec :: Int -> VersionIntervals -> ShowS Source # show :: VersionIntervals -> String Source # showList :: [VersionIntervals] -> ShowS Source #

toVersionIntervals :: VersionRange -> VersionIntervals #

Convert a `VersionRange` to a sequence of version intervals.

fromVersionIntervals :: VersionIntervals -> VersionRange #

Convert a `VersionIntervals` value back into a `VersionRange` expression representing the version intervals.

withinIntervals :: Version -> VersionIntervals -> Bool #

Test if a version falls within the version intervals.

It exists mostly for completeness and testing. It satisfies the following properties:

    withinIntervals v (toVersionIntervals vr) = withinRange v vr
    withinIntervals v ivs = withinRange v (fromVersionIntervals ivs)

versionIntervals :: VersionIntervals -> [VersionInterval] #

Inspect the list of version intervals.

mkVersionIntervals :: [VersionInterval] -> VersionIntervals #

Directly construct a `VersionIntervals` from a list of intervals.

In `Cabal-2.2` the `Maybe` is dropped from the result type.

unionVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals #

intersectVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals #

invertVersionIntervals :: VersionIntervals -> VersionIntervals #

relaxLastInterval :: VersionIntervals -> VersionIntervals #

relaxHeadInterval :: VersionIntervals -> VersionIntervals #

# Version intervals view

asVersionIntervals :: VersionRange -> [VersionInterval] #

View a `VersionRange` as a union of intervals.

This provides a canonical view of the semantics of a `VersionRange` as opposed to the syntax of the expression used to define it. For the syntactic view use `foldVersionRange`.

Each interval is non-empty. The sequence is in increasing order and no intervals overlap or touch. Therefore only the first and last can be unbounded. The sequence can be empty if the range is empty (e.g. a range expression like `&& 2`).

Other checks are trivial to implement using this view. For example:

    isNoVersion vr | [] <- asVersionIntervals vr = True
                   | otherwise                   = False

    isSpecificVersion vr
       | [(LowerBound v  InclusiveBound
          ,UpperBound v' InclusiveBound)] <- asVersionIntervals vr
       , v == v'   = Just v
       | otherwise = Nothing

type VersionInterval = (LowerBound, UpperBound) #

data LowerBound #

Constructors

LowerBound Version !Bound |

Instances

Eq LowerBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods (==) :: LowerBound -> LowerBound -> Bool # (/=) :: LowerBound -> LowerBound -> Bool #
Ord LowerBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods compare :: LowerBound -> LowerBound -> Ordering # (<) :: LowerBound -> LowerBound -> Bool # (<=) :: LowerBound -> LowerBound -> Bool # (>) :: LowerBound -> LowerBound -> Bool # (>=) :: LowerBound -> LowerBound -> Bool # max :: LowerBound -> LowerBound -> LowerBound # min :: LowerBound -> LowerBound -> LowerBound #
Show LowerBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods showsPrec :: Int -> LowerBound -> ShowS Source # show :: LowerBound -> String Source # showList :: [LowerBound] -> ShowS Source #

data UpperBound #

Constructors

NoUpperBound |
UpperBound Version !Bound |

Instances

Eq UpperBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods (==) :: UpperBound -> UpperBound -> Bool # (/=) :: UpperBound -> UpperBound -> Bool #
Ord UpperBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods compare :: UpperBound -> UpperBound -> Ordering # (<) :: UpperBound -> UpperBound -> Bool # (<=) :: UpperBound -> UpperBound -> Bool # (>) :: UpperBound -> UpperBound -> Bool # (>=) :: UpperBound -> UpperBound -> Bool # max :: UpperBound -> UpperBound -> UpperBound # min :: UpperBound -> UpperBound -> UpperBound #
Show UpperBound # |
Instance details Defined in Distribution.Types.VersionInterval Methods showsPrec :: Int -> UpperBound -> ShowS Source # show :: UpperBound -> String Source # showList :: [UpperBound] -> ShowS Source #

data Bound #

Constructors

ExclusiveBound |
InclusiveBound |

Instances

Eq Bound # |
Instance details Defined in Distribution.Types.VersionInterval Methods (==) :: Bound -> Bound -> Bool # (/=) :: Bound -> Bound -> Bool #
Show Bound # |
Instance details Defined in Distribution.Types.VersionInterval Methods showsPrec :: Int -> Bound -> ShowS Source # show :: Bound -> String Source # showList :: [Bound] -> ShowS Source #