HORIZON HASKELLDocslts/ghc-9.14.xb2f3bfd2026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · b2f3bfd · 2026-10-11

ModuleCabal-syntax-3.16.0.0Haskell2010

Distribution.Types.VersionRange

  • 2 types
  • 32 values

Version Range

1 declaration
datadata VersionRange
#
Instances13Eq, Data, Ord, Read, Show, Generic, …

Predicates

The parsed VersionRange of each version constraint used in the examples for hasUpperBound and hasLowerBound are:

Example4 expressions
simpleParsec "< 1" :: Maybe VersionRangeJust (EarlierVersion (mkVersion [1]))simpleParsec ">= 0 && < 1" :: Maybe VersionRangeJust (IntersectVersionRanges (OrLaterVersion (mkVersion [0])) (EarlierVersion (mkVersion [1])))simpleParsec ">= 0 || < 1" :: Maybe VersionRangeJust (UnionVersionRanges (OrLaterVersion (mkVersion [0])) (EarlierVersion (mkVersion [1])))simpleParsec "^>= 4.20.0.0" :: Maybe VersionRangeJust (MajorBoundVersion (mkVersion [4,20,0,0]))

Lower Bound

Does the version range have an explicit lower bound?

Note: this function only considers the user-specified lower bounds, but not the implicit >=0 lower bound.

Example1 expression
forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "^>= 4.20.0.0"] (fmap hasLowerBound . simpleParsec)Just [False,True,False,True]

Is the lower bound version range greater than (GT, >)?

Example1 expression
forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "> 0 && < 1", "> 0 || < 1", "^>= 4.20.0.0"] (fmap hasGTLowerBound . simpleParsec)Just [False,False,False,True,True,False]

Upper Bound

Does the version range have an upper bound?

Example1 expression
forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "^>= 4.20.0.0"] (fmap hasUpperBound . simpleParsec)Just [True,True,False,True]

Is the upper bound version range (less than or equal (LE, <=)?

Example1 expression
forM ["< 1", "<= 1", ">= 0 && < 1", ">= 0 || < 1", ">= 0 && <= 1", ">= 0 || <= 1", "^>= 4.20.0.0"] (fmap hasLEUpperBound . simpleParsec)Just [False,True,False,False,True,True,False]

Does the upper bound version range have a trailing zero?

Example1 expression
forM ["< 1", "< 1.1", "< 1.0", "< 1.1.0", "^>= 4.20.0.0"] (fmap hasTrailingZeroUpperBound . simpleParsec)Just [False,False,True,True,False]

Any Version

Does this VersionRange place any restriction on the Version or is it in fact equivalent to AnyVersion.

Note this is a semantic check, not simply a syntactic check. So for example the following is True (for all v).

isAnyVersion (EarlierVersion v `UnionVersionRanges` orLaterVersion v)

Constructing

The version range -any. That is, a version range containing all versions.

withinRange v anyVersion = True

The empty version range -none, that is a version range containing no versions.

This can be constructed using any unsatisfiable version range expression, for example < 0.

withinRange v noVersion = False

The version range == v.*.

For example, for version 1.2, the version range == 1.2.* is the same as >= 1.2 && < 1.3.

withinRange v' (withinVersion v) = v' >= v && v' < upper v
  where
    upper (Version lower t) = Version (init lower ++ [last lower + 1]) t

The version range ^>= v.

For example, for version 1.2.3.4, the version range ^>= 1.2.3.4 is the same as >= 1.2.3.4 && < 1.3.

Note that ^>= 1 is equivalent to >= 1 && < 1.1.

Modification

Inspection

valuefoldVersionRange
  1. :: a

    "-any" version

  2. -> (Version -> a)
    "== v"
  3. -> (Version -> a)
    "> v"
  4. -> (Version -> a)
    "< v"
  5. -> (a -> a -> a)

    "_ || _" union

  6. -> (a -> a -> a)

    "_ && _" intersection

  7. -> VersionRange
  8. -> a
#

Fold over the basic syntactic structure of a VersionRange.

This provides a syntactic view of the expression defining the version range. The syntactic sugar ">= v", "<= v" and "== v.*" is presented in terms of the other basic syntax.

For a semantic view use asVersionIntervals.

Parser

Version F-Algebra

9 declarations
datadata VersionRangeF a
#

F-Algebra of VersionRange. See cataVersionRange.

Constructors

Instances9Functor, Foldable, Traversable, Eq, Data, Read, …

Version Utilities

3 declarations

Increment the last version number.

Example: For 1.2 this returns 1.3 so that it can be used as upper bound when resolving == 1.2.*. For 0.4.1 it returns 0.4.2.

Compute next greater major version to be used as upper bound.

Example: 0.4.1 produces the version 0.5 which then can be used to construct a range >= 0.4.1 && < 0.5