Copyright | Isaac Jones Simon Marlow 2003-2004 Duncan Coutts 2008 |
---|---|
License | BSD3 |
Maintainer | cabal-devel@haskell.org |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- data 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
- 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
- normaliseVersionRange :: VersionRange -> VersionRange
- stripParensVersionRange :: VersionRange -> VersionRange
- hasUpperBound :: VersionRange -> Bool
- hasLowerBound :: VersionRange -> Bool
- data VersionRangeF 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
- data Bound
- 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
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: 2.0.0.2
Instances
mkVersion :: [Int] -> Version Source #
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: 2.0.0.2
mkVersion' :: Version -> Version Source #
Variant of mkVersion
which converts a Data.Version
Version
into Cabal's Version
type.
Since: 2.0.0.2
versionNumbers :: Version -> [Int] Source #
nullVersion :: Version Source #
Constant representing the special null Version
The nullVersion
compares (via Ord
) as less than every proper
Version
value.
Since: 2.0.0.2
alterVersion :: ([Int] -> [Int]) -> Version -> Version Source #
Apply function to list of version number components
alterVersion f == mkVersion . f . versionNumbers
Since: 2.0.0.2
Version ranges
data VersionRange Source #
Instances
Eq VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal (==) :: VersionRange -> VersionRange -> Bool # (/=) :: VersionRange -> VersionRange -> Bool # | |
Data VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VersionRange -> c VersionRange # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c VersionRange # toConstr :: VersionRange -> Constr # dataTypeOf :: VersionRange -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c VersionRange) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c VersionRange) # gmapT :: (forall b. Data b => b -> b) -> VersionRange -> VersionRange # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VersionRange -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VersionRange -> r # gmapQ :: (forall d. Data d => d -> u) -> VersionRange -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> VersionRange -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionRange -> m VersionRange # | |
Read VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal readsPrec :: Int -> ReadS VersionRange # readList :: ReadS [VersionRange] # | |
Show VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal showsPrec :: Int -> VersionRange -> ShowS # show :: VersionRange -> String # showList :: [VersionRange] -> ShowS # | |
Generic VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal type Rep VersionRange :: Type -> Type # from :: VersionRange -> Rep VersionRange x # to :: Rep VersionRange x -> VersionRange # | |
Binary VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal | |
NFData VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal rnf :: VersionRange -> () # | |
Structured VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal structure :: Proxy VersionRange -> Structure Source # structureHash' :: Tagged VersionRange MD5 | |
Pretty VersionRange Source # |
|
Defined in Distribution.Types.VersionRange.Internal pretty :: VersionRange -> Doc Source # prettyVersioned :: CabalSpecVersion -> VersionRange -> Doc Source # | |
Parsec VersionRange Source # |
Small history:
Set operations are introduced in 3.0
Operators are introduced in 1.8. Issues only a warning.
Wild-version ranges are introduced in 1.6. Issues only a warning.
|
Defined in Distribution.Types.VersionRange.Internal parsec :: CabalParsing m => m VersionRange Source # | |
Newtype (CompilerFlavor, VersionRange) TestedWith Source # | |
Defined in Distribution.FieldGrammar.Newtypes pack :: (CompilerFlavor, VersionRange) -> TestedWith Source # unpack :: TestedWith -> (CompilerFlavor, VersionRange) Source # | |
type Rep VersionRange Source # | |
Defined in Distribution.Types.VersionRange.Internal type Rep VersionRange = D1 ('MetaData "VersionRange" "Distribution.Types.VersionRange.Internal" "Cabal-3.4.1.0-6DL0OBffl0FKxcw4uMtLyp" 'False) (((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 "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))))) |
Constructing
anyVersion :: VersionRange Source #
The version range -any
. That is, a version range containing all
versions.
withinRange v anyVersion = True
noVersion :: VersionRange Source #
The empty version range, 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
thisVersion :: Version -> VersionRange Source #
The version range == v
withinRange v' (thisVersion v) = v' == v
notThisVersion :: Version -> VersionRange Source #
The version range || v
withinRange v' (notThisVersion v) = v' /= v
laterVersion :: Version -> VersionRange Source #
The version range > v
withinRange v' (laterVersion v) = v' > v
earlierVersion :: Version -> VersionRange Source #
The version range < v
withinRange v' (earlierVersion v) = v' < v
orLaterVersion :: Version -> VersionRange Source #
The version range >= v
withinRange v' (orLaterVersion v) = v' >= v
orEarlierVersion :: Version -> VersionRange Source #
The version range <= v
withinRange v' (orEarlierVersion v) = v' <= v
unionVersionRanges :: VersionRange -> VersionRange -> VersionRange Source #
The version range vr1 || vr2
withinRange v' (unionVersionRanges vr1 vr2) = withinRange v' vr1 || withinRange v' vr2
intersectVersionRanges :: VersionRange -> VersionRange -> VersionRange Source #
The version range vr1 && vr2
withinRange v' (intersectVersionRanges vr1 vr2) = withinRange v' vr1 && withinRange v' vr2
differenceVersionRanges :: VersionRange -> VersionRange -> VersionRange Source #
The difference of two version ranges
withinRange v' (differenceVersionRanges vr1 vr2) = withinRange v' vr1 && not (withinRange v' vr2)
Since: 1.24.1.0
invertVersionRange :: VersionRange -> VersionRange Source #
The inverse of a version range
withinRange v' (invertVersionRange vr) = not (withinRange v' vr)
withinVersion :: Version -> VersionRange Source #
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 Source #
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: 2.0.0.2
Inspection
withinRange :: Version -> VersionRange -> Bool Source #
Does this version fall within the given range?
This is the evaluation function for the VersionRange
type.
isAnyVersion :: VersionRange -> Bool Source #
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 Source #
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 Source #
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 Source #
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'
:: a |
|
-> (Version -> a) | "== v" |
-> (Version -> a) | "> v" |
-> (Version -> a) | "< v" |
-> (a -> a -> a) |
|
-> (a -> a -> a) |
|
-> 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
.
normaliseVersionRange :: VersionRange -> VersionRange Source #
Normalise VersionRange
.
In particular collapse (== v || > v)
into >= v
, and so on.
stripParensVersionRange :: VersionRange -> VersionRange Source #
Remove VersionRangeParens
constructors.
Since version 3.4 this function is id
, there aren't VersionRangeParens
constructor in VersionRange
anymore.
Since: 2.2
hasUpperBound :: VersionRange -> Bool Source #
Does the version range have an upper bound?
Since: 1.24.0.0
hasLowerBound :: VersionRange -> Bool Source #
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: 1.24.0.0
Cata & ana
data VersionRangeF a Source #
F-Algebra of VersionRange
. See cataVersionRange
.
Since: 2.2
ThisVersionF Version | |
LaterVersionF Version | |
OrLaterVersionF Version | |
EarlierVersionF Version | |
OrEarlierVersionF Version | |
MajorBoundVersionF Version | |
UnionVersionRangesF a a | |
IntersectVersionRangesF a a |
Instances
cataVersionRange :: (VersionRangeF a -> a) -> VersionRange -> a Source #
Fold VersionRange
.
Since: 2.2
anaVersionRange :: (a -> VersionRangeF a) -> a -> VersionRange Source #
Unfold VersionRange
.
Since: 2.2
hyloVersionRange :: (VersionRangeF VersionRange -> VersionRange) -> (VersionRange -> VersionRangeF VersionRange) -> VersionRange -> VersionRange Source #
Refold VersionRange
Since: 2.2
projectVersionRange :: VersionRange -> VersionRangeF VersionRange Source #
Since: 2.2
embedVersionRange :: VersionRangeF VersionRange -> VersionRange Source #
Since: 2.2
Utilities
wildcardUpperBound :: Version -> Version Source #
Since: 2.2
majorUpperBound :: Version -> Version Source #
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: 2.2
Modification
removeUpperBound :: VersionRange -> VersionRange Source #
Given a version range, remove the highest upper bound. Example: (>= 1 && <
3) || (>= 4 && < 5)
is converted to (>= 1 && || (= 4)
.
Version intervals view
asVersionIntervals :: VersionRange -> [VersionInterval] Source #
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) Source #
data LowerBound Source #
Instances
Eq LowerBound Source # | |
Defined in Distribution.Types.VersionInterval (==) :: LowerBound -> LowerBound -> Bool # (/=) :: LowerBound -> LowerBound -> Bool # | |
Ord LowerBound Source # | |
Defined in Distribution.Types.VersionInterval 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 Source # | |
Defined in Distribution.Types.VersionInterval showsPrec :: Int -> LowerBound -> ShowS # show :: LowerBound -> String # showList :: [LowerBound] -> ShowS # |
data UpperBound Source #
Instances
Eq UpperBound Source # | |
Defined in Distribution.Types.VersionInterval (==) :: UpperBound -> UpperBound -> Bool # (/=) :: UpperBound -> UpperBound -> Bool # | |
Ord UpperBound Source # | |
Defined in Distribution.Types.VersionInterval 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 Source # | |
Defined in Distribution.Types.VersionInterval showsPrec :: Int -> UpperBound -> ShowS # show :: UpperBound -> String # showList :: [UpperBound] -> ShowS # |
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 Source #
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 Source # | |
Defined in Distribution.Types.VersionInterval (==) :: VersionIntervals -> VersionIntervals -> Bool # (/=) :: VersionIntervals -> VersionIntervals -> Bool # | |
Show VersionIntervals Source # | |
Defined in Distribution.Types.VersionInterval showsPrec :: Int -> VersionIntervals -> ShowS # show :: VersionIntervals -> String # showList :: [VersionIntervals] -> ShowS # |
toVersionIntervals :: VersionRange -> VersionIntervals Source #
Convert a VersionRange
to a sequence of version intervals.
fromVersionIntervals :: VersionIntervals -> VersionRange Source #
Convert a VersionIntervals
value back into a VersionRange
expression
representing the version intervals.
withinIntervals :: Version -> VersionIntervals -> Bool Source #
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] Source #
Inspect the list of version intervals.
mkVersionIntervals :: [VersionInterval] -> VersionIntervals Source #
Directly construct a VersionIntervals
from a list of intervals.
In Cabal-2.2
the Maybe
is dropped from the result type.