module Distribution.Version (
Version,
version0,
mkVersion,
mkVersion',
versionNumbers,
nullVersion,
alterVersion,
VersionRange,
anyVersion, noVersion,
thisVersion, notThisVersion,
laterVersion, earlierVersion,
orLaterVersion, orEarlierVersion,
unionVersionRanges, intersectVersionRanges,
differenceVersionRanges,
invertVersionRange,
withinVersion,
majorBoundVersion,
withinRange,
isAnyVersion,
isNoVersion,
isSpecificVersion,
simplifyVersionRange,
foldVersionRange,
normaliseVersionRange,
stripParensVersionRange,
hasUpperBound,
hasLowerBound,
VersionRangeF (..),
cataVersionRange,
anaVersionRange,
hyloVersionRange,
projectVersionRange,
embedVersionRange,
wildcardUpperBound,
majorUpperBound,
removeUpperBound,
removeLowerBound,
asVersionIntervals,
VersionInterval,
LowerBound(..),
UpperBound(..),
Bound(..),
VersionIntervals,
toVersionIntervals,
fromVersionIntervals,
withinIntervals,
versionIntervals,
mkVersionIntervals,
unionVersionIntervals,
intersectVersionIntervals,
invertVersionIntervals
) where
import Distribution.Types.Version
import Distribution.Types.VersionRange
import Distribution.Types.VersionInterval
isNoVersion :: VersionRange -> Bool
isNoVersion :: VersionRange -> Bool
isNoVersion VersionRange
vr = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
vr of
[] -> Bool
True
[VersionInterval]
_ -> Bool
False
isSpecificVersion :: VersionRange -> Maybe Version
isSpecificVersion :: VersionRange -> Maybe Version
isSpecificVersion VersionRange
vr = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
vr of
[(LowerBound Version
v Bound
InclusiveBound
,UpperBound Version
v' Bound
InclusiveBound)]
| Version
v Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
v' -> Version -> Maybe Version
forall a. a -> Maybe a
Just Version
v
[VersionInterval]
_ -> Maybe Version
forall a. Maybe a
Nothing
simplifyVersionRange :: VersionRange -> VersionRange
simplifyVersionRange :: VersionRange -> VersionRange
simplifyVersionRange VersionRange
vr
| [VersionInterval] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (VersionIntervals -> [VersionInterval]
versionIntervals VersionIntervals
vi) = VersionRange
vr
| Bool
otherwise = VersionIntervals -> VersionRange
fromVersionIntervals VersionIntervals
vi
where
vi :: VersionIntervals
vi = VersionRange -> VersionIntervals
toVersionIntervals VersionRange
vr
differenceVersionRanges :: VersionRange -> VersionRange -> VersionRange
differenceVersionRanges :: VersionRange -> VersionRange -> VersionRange
differenceVersionRanges VersionRange
vr1 VersionRange
vr2 =
VersionRange -> VersionRange -> VersionRange
intersectVersionRanges VersionRange
vr1 (VersionRange -> VersionRange
invertVersionRange VersionRange
vr2)
invertVersionRange :: VersionRange -> VersionRange
invertVersionRange :: VersionRange -> VersionRange
invertVersionRange =
VersionIntervals -> VersionRange
fromVersionIntervals (VersionIntervals -> VersionRange)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionIntervals -> VersionIntervals
invertVersionIntervals (VersionIntervals -> VersionIntervals)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionIntervals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionIntervals
toVersionIntervals
removeUpperBound :: VersionRange -> VersionRange
removeUpperBound :: VersionRange -> VersionRange
removeUpperBound = VersionIntervals -> VersionRange
fromVersionIntervals (VersionIntervals -> VersionRange)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionIntervals -> VersionIntervals
relaxLastInterval (VersionIntervals -> VersionIntervals)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionIntervals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionIntervals
toVersionIntervals
removeLowerBound :: VersionRange -> VersionRange
removeLowerBound :: VersionRange -> VersionRange
removeLowerBound = VersionIntervals -> VersionRange
fromVersionIntervals (VersionIntervals -> VersionRange)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionRange
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionIntervals -> VersionIntervals
relaxHeadInterval (VersionIntervals -> VersionIntervals)
-> (VersionRange -> VersionIntervals)
-> VersionRange
-> VersionIntervals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionIntervals
toVersionIntervals