Cabal-1.8.0.2: A framework for packaging Haskell softwareSource codeContentsIndex
Distribution.Version
Portabilityportable
Maintainercabal-devel@haskell.org
Contents
Package versions
Version ranges
Constructing
Inspection
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 = Version {
versionBranch :: [Int]
versionTags :: [String]
}
data VersionRange
= AnyVersion
| ThisVersion Version
| LaterVersion Version
| EarlierVersion Version
| WildcardVersion Version
| UnionVersionRanges VersionRange VersionRange
| IntersectVersionRanges VersionRange 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
withinVersion :: 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) -> (a -> a -> a) -> (a -> a -> a) -> VersionRange -> a
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] -> Maybe VersionIntervals
unionVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals
intersectVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervals
Package versions
data Version Source

A Version represents the version of a software entity.

An instance of Eq is provided, which implements exact equality modulo reordering of the tags in the versionTags field.

An instance of Ord is also provided, which gives lexicographic ordering on the versionBranch fields (i.e. 2.1 > 2.0, 1.2.3 > 1.2.2, etc.). This is expected to be sufficient for many uses, but note that you may need to use a more specific ordering for your versioning scheme. For example, some versioning schemes may include pre-releases which have tags "pre1", "pre2", and so on, and these would need to be taken into account when determining ordering. In some cases, date ordering may be more appropriate, so the application would have to look for date tags in the versionTags field and compare those. The bottom line is, don't always assume that compare and other Ord operations are the right thing for every Version.

Similarly, concrete representations of versions may differ. One possible concrete representation is provided (see showVersion and parseVersion), but depending on the application a different concrete representation may be more appropriate.

Constructors
Version
versionBranch :: [Int]

The numeric branch for this version. This reflects the fact that most software versions are tree-structured; there is a main trunk which is tagged with versions at various points (1,2,3...), and the first branch off the trunk after version 3 is 3.1, the second branch off the trunk after version 3 is 3.2, and so on. The tree can be branched arbitrarily, just by adding more digits.

We represent the branch as a list of Int, so version 3.2.1 becomes [3,2,1]. Lexicographic ordering (i.e. the default instance of Ord for [Int]) gives the natural ordering of branches.

versionTags :: [String]A version can be tagged with an arbitrary list of strings. The interpretation of the list of tags is entirely dependent on the entity that this version applies to.
show/hide Instances
Version ranges
data VersionRange Source
Constructors
AnyVersion
ThisVersion Version
LaterVersion Version
EarlierVersion Version
WildcardVersion Version
UnionVersionRanges VersionRange VersionRange
IntersectVersionRanges VersionRange VersionRange
show/hide Instances
Constructing
anyVersion :: VersionRangeSource

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

 withinRange v anyVersion = True
noVersion :: VersionRangeSource

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 anyVersion = False
thisVersion :: Version -> VersionRangeSource

The version range == v

 withinRange v' (thisVersion v) = v' == v
notThisVersion :: Version -> VersionRangeSource

The version range v || v

 withinRange v' (notThisVersion v) = v' /= v
laterVersion :: Version -> VersionRangeSource

The version range > v

 withinRange v' (laterVersion v) = v' > v
earlierVersion :: Version -> VersionRangeSource

The version range < v

 withinRange v' (earlierVersion v) = v' < v
orLaterVersion :: Version -> VersionRangeSource

The version range >= v

 withinRange v' (orLaterVersion v) = v' >= v
orEarlierVersion :: Version -> VersionRangeSource

The version range <= v

 withinRange v' (orEarlierVersion v) = v' <= v
unionVersionRanges :: VersionRange -> VersionRange -> VersionRangeSource

The version range vr1 || vr2

   withinRange v' (unionVersionRanges vr1 vr2)
 = withinRange v' vr1 || withinRange v' vr2
intersectVersionRanges :: VersionRange -> VersionRange -> VersionRangeSource

The version range vr1 && vr2

   withinRange v' (intersectVersionRanges vr1 vr2)
 = withinRange v' vr1 && withinRange v' vr2
withinVersion :: Version -> VersionRangeSource

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
betweenVersionsInclusive :: Version -> Version -> VersionRangeSource

The version range >= v1 && <= v2.

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

 withinRange v' (laterVersion v) = v' > v
Inspection
withinRange :: Version -> VersionRange -> BoolSource

Does this version fall within the given range?

This is the evaluation function for the VersionRange type.

isAnyVersion :: VersionRange -> BoolSource

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

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 VersionSource

Is this version range in fact just a specific version?

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

simplifyVersionRange :: VersionRange -> VersionRangeSource

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'
foldVersionRangeSource
::
=> a
"== v"
-> Version -> a
"> v"
-> Version -> a
"< v"
-> Version -> a"_ || _" union
-> a -> a -> a"_ && _" intersection
-> a -> a -> a
-> VersionRange
-> a

Fold over the basic syntactic structure of a VersionRange.

This provides a syntacic 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'Source
::
=> a
"== v"
-> Version -> a
"> v"
-> Version -> a
"< v"
-> Version -> a
">= v"
-> Version -> a
"<= v"
-> 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"_ || _" union
-> a -> a -> a"_ && _" intersection
-> a -> a -> a
-> VersionRange
-> a
An extended variant of foldVersionRange that also provides a view of in which the syntactic sugar ">= v", "<= v" and "== v.*" is presented explicitly rather than in terms of the other basic syntax.
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 1 && 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
Constructors
LowerBound Version !Bound
show/hide Instances
data UpperBound Source
Constructors
NoUpperBound
UpperBound Version !Bound
show/hide Instances
data Bound Source
Constructors
ExclusiveBound
InclusiveBound
show/hide Instances
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 VersionIntervals.
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 VersionRanges. 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.

show/hide Instances
toVersionIntervals :: VersionRange -> VersionIntervalsSource
Convert a VersionRange to a sequence of version intervals.
fromVersionIntervals :: VersionIntervals -> VersionRangeSource
Convert a VersionIntervals value back into a VersionRange expression representing the version intervals.
withinIntervals :: Version -> VersionIntervals -> BoolSource

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] -> Maybe VersionIntervalsSource

Directly construct a VersionIntervals from a list of intervals.

Each interval must be non-empty. The sequence must be in increasing order and no invervals may overlap or touch. If any of these conditions are not satisfied the function returns Nothing.

unionVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervalsSource
intersectVersionIntervals :: VersionIntervals -> VersionIntervals -> VersionIntervalsSource
Produced by Haddock version 2.6.0