Distribution.Version

Cabal-2.4.0.1: A framework for packaging Haskell software

Copyright | Isaac Jones Simon Marlow 2003-2004 Duncan Coutts 2008
License | BSD3
Maintainer | cabal-devel@haskell.org
Portability | portable
Safe Haskell | None
Language | Haskell2010

Distribution.Version

Contents

- Package versions
  - Backwards compatibility
- Version ranges
  - Constructing
  - Inspection
  - Cata & ana
  - Utilities
  - Modification
- Version intervals view
  - `VersionIntervals` abstract type

Description

Exports the `Version` type along with a parser and pretty printer. A version is something like `"1.3.3"`. It also defines the `VersionRange` data types. Version ranges are like `">= 1.2 && < 2"`.

Synopsis

- data Version
- version0 :: Version
- mkVersion :: [Int] -> Version
- mkVersion' :: Version -> Version
- versionNumbers :: Version -> [Int]
- nullVersion :: Version
- alterVersion :: ([Int] -> [Int]) -> Version -> Version
- showVersion :: Version -> String
- data VersionRange
  - = AnyVersion
  - | ThisVersion Version
  - | LaterVersion Version
  - | OrLaterVersion Version
  - | EarlierVersion Version
  - | OrEarlierVersion Version
  - | WildcardVersion Version
  - | MajorBoundVersion Version
  - | UnionVersionRanges VersionRange VersionRange
  - | IntersectVersionRanges VersionRange VersionRange
  - | VersionRangeParens VersionRange
- anyVersion :: VersionRange
- noVersion :: VersionRange
- thisVersion :: Version -> VersionRange
- notThisVersion :: Version -> VersionRange
- laterVersion :: Version -> VersionRange
- earlierVersion :: Version -> VersionRange
- orLaterVersion :: Version -> VersionRange
- orEarlierVersion :: Version -> VersionRange
- unionVersionRanges :: VersionRange -> VersionRange -> VersionRange
- intersectVersionRanges :: VersionRange -> VersionRange -> VersionRange
- differenceVersionRanges :: VersionRange -> VersionRange -> VersionRange
- invertVersionRange :: VersionRange -> VersionRange
- withinVersion :: Version -> VersionRange
- majorBoundVersion :: Version -> VersionRange
- betweenVersionsInclusive :: Version -> Version -> VersionRange
- withinRange :: Version -> VersionRange -> Bool
- isAnyVersion :: VersionRange -> Bool
- isNoVersion :: VersionRange -> Bool
- isSpecificVersion :: VersionRange -> Maybe Version
- simplifyVersionRange :: VersionRange -> VersionRange
- foldVersionRange :: a -> (Version -> a) -> (Version -> a) -> (Version -> a) -> (a -> a -> a) -> (a -> a -> a) -> VersionRange -> a
- foldVersionRange' :: a -> (Version -> a) -> (Version -> a) -> (Version -> a) -> (Version -> a) -> (Version -> a) -> (Version -> Version -> a) -> (Version -> Version -> a) -> (a -> a -> a) -> (a -> a -> a) -> (a -> a) -> VersionRange -> a
- normaliseVersionRange :: VersionRange -> VersionRange
- stripParensVersionRange :: VersionRange -> VersionRange
- hasUpperBound :: VersionRange -> Bool
- hasLowerBound :: VersionRange -> Bool
- data VersionRangeF a
  - = AnyVersionF
  - | ThisVersionF Version
  - | LaterVersionF Version
  - | OrLaterVersionF Version
  - | EarlierVersionF Version
  - | OrEarlierVersionF Version
  - | WildcardVersionF Version
  - | MajorBoundVersionF Version
  - | UnionVersionRangesF a a
  - | IntersectVersionRangesF a a
  - | VersionRangeParensF a
- cataVersionRange :: (VersionRangeF a -> a) -> VersionRange -> a
- anaVersionRange :: (a -> VersionRangeF a) -> a -> VersionRange
- hyloVersionRange :: (VersionRangeF VersionRange -> VersionRange) -> (VersionRange -> VersionRangeF VersionRange) -> VersionRange -> VersionRange
- projectVersionRange :: VersionRange -> VersionRangeF VersionRange
- embedVersionRange :: VersionRangeF VersionRange -> VersionRange
- wildcardUpperBound :: Version -> Version
- majorUpperBound :: Version -> Version
- removeUpperBound :: VersionRange -> VersionRange
- removeLowerBound :: VersionRange -> VersionRange
- asVersionIntervals :: VersionRange -> [VersionInterval]
- type VersionInterval = (LowerBound, UpperBound)
- data LowerBound = LowerBound Version !Bound
- data UpperBound
  - = NoUpperBound
  - | UpperBound Version !Bound
- data Bound
  - = ExclusiveBound
  - | InclusiveBound
- 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

# Package versions

data Version #

A `Version` represents the version of a software entity.

Instances of `Eq` and `Ord` are provided, which gives exact equality and lexicographic ordering of the version number components (i.e. 2.1 > 2.0, 1.2.3 > 1.2.2, etc.).

This type is opaque and distinct from the `Version` type in Data.Version since `Cabal-2.0`. The difference extends to the `Binary` instance using a different (and more compact) encoding.

Since: Cabal-2.0.0.2

Instances

Eq Version # |
Instance details Defined in Distribution.Types.Version Methods (==) :: Version -> Version -> Bool # (/=) :: Version -> Version -> Bool #
Data Version # |
Instance details Defined in Distribution.Types.Version Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Version -> c Version Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Version Source # toConstr :: Version -> Constr Source # dataTypeOf :: Version -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Version) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Version) Source # gmapT :: (forall b. Data b => b -> b) -> Version -> Version Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Version -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Version -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Version -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Version -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Version -> m Version Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Version -> m Version Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Version -> m Version Source #
Ord Version # |
Instance details Defined in Distribution.Types.Version Methods compare :: Version -> Version -> Ordering # (<) :: Version -> Version -> Bool # (<=) :: Version -> Version -> Bool # (>) :: Version -> Version -> Bool # (>=) :: Version -> Version -> Bool # max :: Version -> Version -> Version # min :: Version -> Version -> Version #
Read Version # |
Instance details Defined in Distribution.Types.Version Methods readsPrec :: Int -> ReadS Version Source # readList :: ReadS [Version] Source # readPrec :: ReadPrec Version Source # readListPrec :: ReadPrec [Version] Source #
Show Version # |
Instance details Defined in Distribution.Types.Version Methods showsPrec :: Int -> Version -> ShowS Source # show :: Version -> String Source # showList :: [Version] -> ShowS Source #
Generic Version # |
Instance details Defined in Distribution.Types.Version Associated Types type Rep Version :: Type -> Type Source # Methods from :: Version -> Rep Version x Source # to :: Rep Version x -> Version Source #
Binary Version # |
Instance details Defined in Distribution.Types.Version Methods put :: Version -> Put Source # get :: Get Version Source # putList :: [Version] -> Put Source #
NFData Version # |
Instance details Defined in Distribution.Types.Version Methods rnf :: Version -> () Source #
Pretty Version # |
Instance details Defined in Distribution.Types.Version Methods pretty :: Version -> Doc #
Parsec Version # |
Instance details Defined in Distribution.Types.Version Methods parsec :: CabalParsing m => m Version #
Text Version # |
Instance details Defined in Distribution.Types.Version Methods disp :: Version -> Doc # parse :: ReadP r Version #
Newtype SpecVersion (Either Version VersionRange) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: Either Version VersionRange -> SpecVersion # unpack :: SpecVersion -> Either Version VersionRange #
type Rep Version # |
Instance details Defined in Distribution.Types.Version type Rep Version = D1 (MetaData "Version" "Distribution.Types.Version" "Cabal-2.4.0.1" False) (C1 (MetaCons "PV0" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) SourceUnpack SourceStrict DecidedStrict) (Rec0 Word64)) :+: C1 (MetaCons "PV1" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Int])))

version0 :: Version #

Version 0. A lower bound of `Version`.

Since: Cabal-2.2

mkVersion :: [Int] -> Version #

Construct `Version` from list of version number components.

For instance, `mkVersion [3,2,1]` constructs a `Version` representing the version `3.2.1`.

All version components must be non-negative. `mkVersion []` currently represents the special null version; see also `nullVersion`.

Since: Cabal-2.0.0.2

mkVersion' :: Version -> Version #

Variant of `mkVersion` which converts a Data.Version `Version` into Cabal's `Version` type.

Since: Cabal-2.0.0.2

versionNumbers :: Version -> [Int] #

Unpack `Version` into list of version number components.

This is the inverse to `mkVersion`, so the following holds:

    (versionNumbers . mkVersion) vs == vs

Since: Cabal-2.0.0.2

nullVersion :: Version #

Constant representing the special null `Version`

The `nullVersion` compares (via `Ord`) as less than every proper `Version` value.

Since: Cabal-2.0.0.2

alterVersion :: ([Int] -> [Int]) -> Version -> Version #

Apply function to list of version number components

    alterVersion f == mkVersion . f . versionNumbers

Since: Cabal-2.0.0.2

## Backwards compatibility

showVersion :: Version -> String #

Deprecated: Use prettyShow. This function will be removed in Cabal-3.0 (estimated Oct 2018)

# Version ranges

data VersionRange #

Constructors

AnyVersion | Deprecated: Use `anyVersion`, `foldVersionRange` or `asVersionIntervals`
ThisVersion Version | Deprecated: Use `thisVersion`, `foldVersionRange` or `asVersionIntervals`
LaterVersion Version | Deprecated: Use `laterVersion`, `foldVersionRange` or `asVersionIntervals`
OrLaterVersion Version |
EarlierVersion Version | Deprecated: Use `earlierVersion`, `foldVersionRange` or `asVersionIntervals`
OrEarlierVersion Version |
WildcardVersion Version | Deprecated: Use `anyVersion`, `foldVersionRange` or `asVersionIntervals`
MajorBoundVersion Version |
UnionVersionRanges VersionRange VersionRange | Deprecated: Use `unionVersionRanges`, `foldVersionRange` or `asVersionIntervals`
IntersectVersionRanges VersionRange VersionRange | Deprecated: Use `intersectVersionRanges`, `foldVersionRange` or `asVersionIntervals`
VersionRangeParens VersionRange |

Instances

Eq VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods (==) :: VersionRange -> VersionRange -> Bool # (/=) :: VersionRange -> VersionRange -> Bool #
Data VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VersionRange -> c VersionRange Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c VersionRange Source # toConstr :: VersionRange -> Constr Source # dataTypeOf :: VersionRange -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c VersionRange) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c VersionRange) Source # gmapT :: (forall b. Data b => b -> b) -> VersionRange -> VersionRange Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VersionRange -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VersionRange -> r Source # gmapQ :: (forall d. Data d => d -> u) -> VersionRange -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> VersionRange -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange Source #
Read VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods readsPrec :: Int -> ReadS VersionRange Source # readList :: ReadS [VersionRange] Source # readPrec :: ReadPrec VersionRange Source # readListPrec :: ReadPrec [VersionRange] Source #
Show VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods showsPrec :: Int -> VersionRange -> ShowS Source # show :: VersionRange -> String Source # showList :: [VersionRange] -> ShowS Source #
Generic VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Associated Types type Rep VersionRange :: Type -> Type Source # Methods from :: VersionRange -> Rep VersionRange x Source # to :: Rep VersionRange x -> VersionRange Source #
Binary VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods put :: VersionRange -> Put Source # get :: Get VersionRange Source # putList :: [VersionRange] -> Put Source #
NFData VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods rnf :: VersionRange -> () Source #
Pretty VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods pretty :: VersionRange -> Doc #
Parsec VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods parsec :: CabalParsing m => m VersionRange #
Text VersionRange # |
Instance details Defined in Distribution.Types.VersionRange Methods disp :: VersionRange -> Doc # parse :: ReadP r VersionRange #
Newtype TestedWith (CompilerFlavor, VersionRange) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: (CompilerFlavor, VersionRange) -> TestedWith # unpack :: TestedWith -> (CompilerFlavor, VersionRange) #
Newtype SpecVersion (Either Version VersionRange) # |
Instance details Defined in Distribution.Parsec.Newtypes Methods pack :: Either Version VersionRange -> SpecVersion # unpack :: SpecVersion -> Either Version VersionRange #
type Rep VersionRange # |
Instance details Defined in Distribution.Types.VersionRange type Rep VersionRange = D1 (MetaData "VersionRange" "Distribution.Types.VersionRange" "Cabal-2.4.0.1" False) (((C1 (MetaCons "AnyVersion" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ThisVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version))) :+: (C1 (MetaCons "LaterVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: (C1 (MetaCons "OrLaterVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: C1 (MetaCons "EarlierVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version))))) :+: ((C1 (MetaCons "OrEarlierVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: (C1 (MetaCons "WildcardVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: C1 (MetaCons "MajorBoundVersion" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)))) :+: (C1 (MetaCons "UnionVersionRanges" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 VersionRange) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 VersionRange)) :+: (C1 (MetaCons "IntersectVersionRanges" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 VersionRange) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 VersionRange)) :+: C1 (MetaCons "VersionRangeParens" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 VersionRange))))))

## Constructing

anyVersion :: VersionRange #

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

    withinRange v anyVersion = True

noVersion :: VersionRange #

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

This can be constructed using any unsatisfiable version range expression, for example `> 1 && < 1`.

    withinRange v noVersion = False

thisVersion :: Version -> VersionRange #

The version range `== v`

    withinRange v' (thisVersion v) = v' == v

notThisVersion :: Version -> VersionRange #

The version range `|| v`

    withinRange v' (notThisVersion v) = v' /= v

laterVersion :: Version -> VersionRange #

The version range `> v`

    withinRange v' (laterVersion v) = v' > v

earlierVersion :: Version -> VersionRange #

The version range `< v`

    withinRange v' (earlierVersion v) = v' < v

orLaterVersion :: Version -> VersionRange #

The version range `>= v`

    withinRange v' (orLaterVersion v) = v' >= v

orEarlierVersion :: Version -> VersionRange #

The version range `<= v`

    withinRange v' (orEarlierVersion v) = v' <= v

unionVersionRanges :: VersionRange -> VersionRange -> VersionRange #

The version range `vr1 || vr2`

      withinRange v' (unionVersionRanges vr1 vr2)
    = withinRange v' vr1 || withinRange v' vr2

intersectVersionRanges :: VersionRange -> VersionRange -> VersionRange #

The version range `vr1 && vr2`

      withinRange v' (intersectVersionRanges vr1 vr2)
    = withinRange v' vr1 && withinRange v' vr2

differenceVersionRanges :: VersionRange -> VersionRange -> VersionRange #

The difference of two version ranges

      withinRange v' (differenceVersionRanges vr1 vr2)
    = withinRange v' vr1 && not (withinRange v' vr2)

Since: Cabal-1.24.1.0

invertVersionRange :: VersionRange -> VersionRange #

The inverse of a version range

      withinRange v' (invertVersionRange vr)
    = not (withinRange v' vr)

withinVersion :: Version -> VersionRange #

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' (laterVersion v) = v' >= v && v' < upper v
      where
        upper (Version lower t) = Version (init lower ++ [last lower + 1]) t

majorBoundVersion :: Version -> VersionRange #

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

Since: Cabal-2.0.0.2

betweenVersionsInclusive :: Version -> Version -> VersionRange #

Deprecated: In practice this is not very useful because we normally use inclusive lower bounds and exclusive upper bounds

## Inspection

withinRange :: Version -> VersionRange -> Bool #

Does this version fall within the given range?

This is the evaluation function for the `VersionRange` type.

isAnyVersion :: VersionRange -> Bool #

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)

isNoVersion :: VersionRange -> Bool #

This is the converse of `isAnyVersion`. It check if the version range is empty, if there is no possible version that satisfies the version range.

For example this is `True` (for all `v`):

    isNoVersion (EarlierVersion v `IntersectVersionRanges` LaterVersion v)

isSpecificVersion :: VersionRange -> Maybe Version #

Is this version range in fact just a specific version?

For example the version range `">= 3 && <= 3"` contains only the version `3`.

simplifyVersionRange :: VersionRange -> VersionRange #

Simplify a `VersionRange` expression. For non-empty version ranges this produces a canonical form. Empty or inconsistent version ranges are left as-is because that provides more information.

If you need a canonical form use `fromVersionIntervals . toVersionIntervals`

It satisfies the following properties:

    withinRange v (simplifyVersionRange r) = withinRange v r

        withinRange v r = withinRange v r'
    ==> simplifyVersionRange r = simplifyVersionRange r'
     || isNoVersion r
     || isNoVersion r'

foldVersionRange #

Arguments

:: a | `"-any"` version
-> (Version -> a) |
    "== v"
-> (Version -> a) |
    "> v"
-> (Version -> a) |
    "< v"
-> (a -> a -> a) | `"_ || _"` union
-> (a -> a -> a) | `"_ && _"` intersection
-> VersionRange |
-> 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`.

foldVersionRange' #

Arguments

:: a | `"-any"` version
-> (Version -> a) |
    "== v"
-> (Version -> a) |
    "> v"
-> (Version -> a) |
    "< v"
-> (Version -> a) |
    ">= v"
-> (Version -> a) |
    "<= v"
-> (Version -> Version -> a) | `"== v.*"` wildcard. The function is passed the inclusive lower bound and the exclusive upper bounds of the range defined by the wildcard.
-> (Version -> Version -> a) | `"^>= v"` major upper bound The function is passed the inclusive lower bound and the exclusive major upper bounds of the range defined by this operator.
-> (a -> a -> a) | `"_ || _"` union
-> (a -> a -> a) | `"_ && _"` intersection
-> (a -> a) | `"(_)"` parentheses
-> VersionRange |
-> a |

Deprecated: Use cataVersionRange & normaliseVersionRange for more principled folding

An extended variant of `foldVersionRange` that also provides a view of the expression in which the syntactic sugar `">= v"`, `"<= v"` and `"== v.*"` is presented explicitly rather than in terms of the other basic syntax.

normaliseVersionRange :: VersionRange -> VersionRange #

Normalise `VersionRange`.

In particular collapse `(== v || > v)` into `>= v`, and so on.

stripParensVersionRange :: VersionRange -> VersionRange #

Remove `VersionRangeParens` constructors.

Since: Cabal-2.2

hasUpperBound :: VersionRange -> Bool #

Does the version range have an upper bound?

Since: Cabal-1.24.0.0

hasLowerBound :: VersionRange -> Bool #

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.

Since: Cabal-1.24.0.0

## Cata & ana

data VersionRangeF a #

F-Algebra of `VersionRange`. See `cataVersionRange`.

Since: Cabal-2.2

Constructors

AnyVersionF |
ThisVersionF Version |
LaterVersionF Version |
OrLaterVersionF Version |
EarlierVersionF Version |
OrEarlierVersionF Version |
WildcardVersionF Version |
MajorBoundVersionF Version |
UnionVersionRangesF a a |
IntersectVersionRangesF a a |
VersionRangeParensF a |

Instances

Functor VersionRangeF # |
Instance details Defined in Distribution.Types.VersionRange Methods fmap :: (a -> b) -> VersionRangeF a -> VersionRangeF b Source # (<$) :: a -> VersionRangeF b -> VersionRangeF a Source #
Foldable VersionRangeF # |
Instance details Defined in Distribution.Types.VersionRange Methods fold :: Monoid m => VersionRangeF m -> m Source # foldMap :: Monoid m => (a -> m) -> VersionRangeF a -> m Source # foldr :: (a -> b -> b) -> b -> VersionRangeF a -> b Source # foldr' :: (a -> b -> b) -> b -> VersionRangeF a -> b Source # foldl :: (b -> a -> b) -> b -> VersionRangeF a -> b Source # foldl' :: (b -> a -> b) -> b -> VersionRangeF a -> b Source # foldr1 :: (a -> a -> a) -> VersionRangeF a -> a Source # foldl1 :: (a -> a -> a) -> VersionRangeF a -> a Source # toList :: VersionRangeF a -> [a] Source # null :: VersionRangeF a -> Bool Source # length :: VersionRangeF a -> Int Source # elem :: Eq a => a -> VersionRangeF a -> Bool Source # maximum :: Ord a => VersionRangeF a -> a Source # minimum :: Ord a => VersionRangeF a -> a Source # sum :: Num a => VersionRangeF a -> a Source # product :: Num a => VersionRangeF a -> a Source #
Traversable VersionRangeF # |
Instance details Defined in Distribution.Types.VersionRange Methods traverse :: Applicative f => (a -> f b) -> VersionRangeF a -> f (VersionRangeF b) Source # sequenceA :: Applicative f => VersionRangeF (f a) -> f (VersionRangeF a) Source # mapM :: Monad m => (a -> m b) -> VersionRangeF a -> m (VersionRangeF b) Source # sequence :: Monad m => VersionRangeF (m a) -> m (VersionRangeF a) Source #
Eq a => Eq (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange Methods (==) :: VersionRangeF a -> VersionRangeF a -> Bool # (/=) :: VersionRangeF a -> VersionRangeF a -> Bool #
Data a => Data (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VersionRangeF a -> c (VersionRangeF a) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (VersionRangeF a) Source # toConstr :: VersionRangeF a -> Constr Source # dataTypeOf :: VersionRangeF a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (VersionRangeF a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (VersionRangeF a)) Source # gmapT :: (forall b. Data b => b -> b) -> VersionRangeF a -> VersionRangeF a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VersionRangeF a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> VersionRangeF a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> VersionRangeF a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> VersionRangeF a -> m (VersionRangeF a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRangeF a -> m (VersionRangeF a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRangeF a -> m (VersionRangeF a) Source #
Read a => Read (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange Methods readsPrec :: Int -> ReadS (VersionRangeF a) Source # readList :: ReadS [VersionRangeF a] Source # readPrec :: ReadPrec (VersionRangeF a) Source # readListPrec :: ReadPrec [VersionRangeF a] Source #
Show a => Show (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange Methods showsPrec :: Int -> VersionRangeF a -> ShowS Source # show :: VersionRangeF a -> String Source # showList :: [VersionRangeF a] -> ShowS Source #
Generic (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange Associated Types type Rep (VersionRangeF a) :: Type -> Type Source # Methods from :: VersionRangeF a -> Rep (VersionRangeF a) x Source # to :: Rep (VersionRangeF a) x -> VersionRangeF a Source #
type Rep (VersionRangeF a) # |
Instance details Defined in Distribution.Types.VersionRange type Rep (VersionRangeF a) = D1 (MetaData "VersionRangeF" "Distribution.Types.VersionRange" "Cabal-2.4.0.1" False) (((C1 (MetaCons "AnyVersionF" PrefixI False) (U1 :: Type -> Type) :+: C1 (MetaCons "ThisVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version))) :+: (C1 (MetaCons "LaterVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: (C1 (MetaCons "OrLaterVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: C1 (MetaCons "EarlierVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version))))) :+: ((C1 (MetaCons "OrEarlierVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: (C1 (MetaCons "WildcardVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)) :+: C1 (MetaCons "MajorBoundVersionF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Version)))) :+: (C1 (MetaCons "UnionVersionRangesF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: (C1 (MetaCons "IntersectVersionRangesF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "VersionRangeParensF" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))))

cataVersionRange :: (VersionRangeF a -> a) -> VersionRange -> a #

Fold `VersionRange`.

Since: Cabal-2.2

anaVersionRange :: (a -> VersionRangeF a) -> a -> VersionRange #

Unfold `VersionRange`.

Since: Cabal-2.2

hyloVersionRange :: (VersionRangeF VersionRange -> VersionRange) -> (VersionRange -> VersionRangeF VersionRange) -> VersionRange -> VersionRange #

Refold `VersionRange`

Since: Cabal-2.2

projectVersionRange :: VersionRange -> VersionRangeF VersionRange #

Since: Cabal-2.2

embedVersionRange :: VersionRangeF VersionRange -> VersionRange #

Since: Cabal-2.2

## Utilities

wildcardUpperBound :: Version -> Version #

Since: Cabal-2.2

majorUpperBound :: Version -> Version #

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`

Since: Cabal-2.2

## Modification

removeUpperBound :: VersionRange -> VersionRange #

Given a version range, remove the highest upper bound. Example: `(>= 1 && < 3) || (>= 4 && < 5)` is converted to `(>= 1 && || (= 4)`.

removeLowerBound :: VersionRange -> VersionRange #

Given a version range, remove the lowest lower bound. Example: `(>= 1 && || (= 4 && < 5)` is converted to `(>= 0 && || (= 4 && < 5)`.

# 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 #

## `VersionIntervals` abstract type

The `VersionIntervals` type and the accompanying functions are exposed primarily for completeness and testing purposes. In practice `asVersionIntervals` is the main function to use to view a `VersionRange` as a bunch of `VersionInterval`s.

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 #