cabal-fmt-0.1.9: Format .cabal files

Safe Haskell | Safe-Inferred
Language | Haskell2010

VersionInterval

Contents

- Version intervals
- Conversions
  - Normalisation
- Version intervals view
- For testing

Description

This module implements a view of a `VersionRange` as a finite list of separated version intervals.

In conversion from and to `VersionRange` it makes some effort to preserve the caret operator `^>=x.y`. This constraint a priori specifies the same interval as `==x.y.*`, but indicates that newer versions could be acceptable (`allow-newer: ^`).

Synopsis

- data VersionIntervals
- unVersionIntervals :: VersionIntervals -> [VersionInterval]
- toVersionIntervals :: VersionRange -> VersionIntervals
- fromVersionIntervals :: VersionIntervals -> Either ConversionProblem VersionRange
- data ConversionProblem
  - = IntervalsEmpty
  - | OtherConversionProblem
- normaliseVersionRange :: VersionRange -> Either ConversionProblem VersionRange
- data VersionInterval = VI !LB !MB !UB
- data LB = LB !Version
- data MB
  - = MB !Version
  - | NoMB
- data UB
  - = UB !Version
  - | NoUB
- data Bound
  - = Incl
  - | Excl
- validVersionInterval :: VersionInterval -> Bool
- validVersionIntervals :: VersionIntervals -> Bool
- intersectInterval :: VersionInterval -> VersionInterval -> Maybe VersionInterval
- stage1 :: ([VersionInterval] -> [VersionInterval]) -> VersionRange -> [VersionInterval]
- stage2 :: [VersionInterval] -> [VersionInterval]
- stage3 :: [VersionInterval] -> [VersionInterval]

# Version intervals

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.

This version is different than in `Cabal-3.8` and previous, as it tries to preserve `^>=` version ranges under default and `transformCaretUpper` semantics. Slighly simplifying, `normalizeVersionRange` shouldn't destroy `^>=` in version range expressions.

#### Instances

Instances details

Show VersionIntervals # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> VersionIntervals -> ShowS show :: VersionIntervals -> String showList :: [VersionIntervals] -> ShowS
Eq VersionIntervals # |
Instance details Defined in VersionInterval Methods (==) :: VersionIntervals -> VersionIntervals -> Bool (/=) :: VersionIntervals -> VersionIntervals -> Bool

unVersionIntervals :: VersionIntervals -> [VersionInterval] #

Inspect the list of version intervals.

# Conversions

toVersionIntervals :: VersionRange -> VersionIntervals #

Convert a `VersionRange` to a sequence of version intervals.

fromVersionIntervals :: VersionIntervals -> Either ConversionProblem VersionRange #

Convert a `VersionIntervals` value back into a `VersionRange` expression representing the version intervals.

data ConversionProblem #

Constructors

IntervalsEmpty |
OtherConversionProblem |

#### Instances

Instances details

Show ConversionProblem # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> ConversionProblem -> ShowS show :: ConversionProblem -> String showList :: [ConversionProblem] -> ShowS
Eq ConversionProblem # |
Instance details Defined in VersionInterval Methods (==) :: ConversionProblem -> ConversionProblem -> Bool (/=) :: ConversionProblem -> ConversionProblem -> Bool

## Normalisation

normaliseVersionRange :: VersionRange -> Either ConversionProblem VersionRange #

Convert `VersionRange` to `VersionIntervals` and back.

# Version intervals view

data VersionInterval #

Version interval.

Invariants:

- Interval is non-empty
- `MB` is between `LB` and `UB`.

Constructors

VI !LB !MB !UB |

#### Instances

Instances details

Show VersionInterval # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> VersionInterval -> ShowS show :: VersionInterval -> String showList :: [VersionInterval] -> ShowS
Eq VersionInterval # |
Instance details Defined in VersionInterval Methods (==) :: VersionInterval -> VersionInterval -> Bool (/=) :: VersionInterval -> VersionInterval -> Bool

data LB #

Lower bound. For intervals it always exist: `zeroLB` i.e. `>= 0`.

All lower bound intervals are inclusive, i.e. `>=v`. `>x.y.z` is converted into `>=x.y.z.0`.

Constructors

LB !Version |

#### Instances

Instances details

Show LB # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> LB -> ShowS show :: LB -> String showList :: [LB] -> ShowS
Eq LB # |
Instance details Defined in VersionInterval Methods (==) :: LB -> LB -> Bool (/=) :: LB -> LB -> Bool
Ord LB # |
Instance details Defined in VersionInterval Methods compare :: LB -> LB -> Ordering (<) :: LB -> LB -> Bool (<=) :: LB -> LB -> Bool (>) :: LB -> LB -> Bool (>=) :: LB -> LB -> Bool max :: LB -> LB -> LB min :: LB -> LB -> LB

data MB #

Middle bound.

Constructors

MB !Version | major bound.
NoMB | no major bound (i.e. infinite)

#### Instances

Instances details

Show MB # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> MB -> ShowS show :: MB -> String showList :: [MB] -> ShowS
Eq MB # |
Instance details Defined in VersionInterval Methods (==) :: MB -> MB -> Bool (/=) :: MB -> MB -> Bool
Ord MB # |
Instance details Defined in VersionInterval Methods compare :: MB -> MB -> Ordering (<) :: MB -> MB -> Bool (<=) :: MB -> MB -> Bool (>) :: MB -> MB -> Bool (>=) :: MB -> MB -> Bool max :: MB -> MB -> MB min :: MB -> MB -> MB

data UB #

Upper bound.

All upper bounds are exclusive, i.e. `<v`. `<=x.y.z` is converted to `<x.y.z.0`.

Constructors

UB !Version | upper bound
NoUB | no upper bound (i.e. infinite)

#### Instances

Instances details

Show UB # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> UB -> ShowS show :: UB -> String showList :: [UB] -> ShowS
Eq UB # |
Instance details Defined in VersionInterval Methods (==) :: UB -> UB -> Bool (/=) :: UB -> UB -> Bool
Ord UB # |
Instance details Defined in VersionInterval Methods compare :: UB -> UB -> Ordering (<) :: UB -> UB -> Bool (<=) :: UB -> UB -> Bool (>) :: UB -> UB -> Bool (>=) :: UB -> UB -> Bool max :: UB -> UB -> UB min :: UB -> UB -> UB

data Bound #

Bound variant.

Constructors

Incl | inclusive: `>=` or `<=`
Excl | exclusive: `>` or `<`

#### Instances

Instances details

Show Bound # |
Instance details Defined in VersionInterval Methods showsPrec :: Int -> Bound -> ShowS show :: Bound -> String showList :: [Bound] -> ShowS
Eq Bound # |
Instance details Defined in VersionInterval Methods (==) :: Bound -> Bound -> Bool (/=) :: Bound -> Bound -> Bool
Ord Bound # |
Instance details Defined in VersionInterval Methods compare :: Bound -> Bound -> Ordering (<) :: Bound -> Bound -> Bool (<=) :: Bound -> Bound -> Bool (>) :: Bound -> Bound -> Bool (>=) :: Bound -> Bound -> Bool max :: Bound -> Bound -> Bound min :: Bound -> Bound -> Bound

# For testing

validVersionInterval :: VersionInterval -> Bool #

validVersionIntervals :: VersionIntervals -> Bool #

`VersionIntervals` invariant:

- all intervals are valid (lower bound is less then upper bound, middle bound is in between)
- intervals doesn't touch each other (distinct)

intersectInterval :: VersionInterval -> VersionInterval -> Maybe VersionInterval #

stage1 :: ([VersionInterval] -> [VersionInterval]) -> VersionRange -> [VersionInterval] #

stage2 :: [VersionInterval] -> [VersionInterval] #

stage3 :: [VersionInterval] -> [VersionInterval] #