Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Internal module. Exposes the invariant-breaking UnsafePackageVersion
constructor.
Since: 0.1.0.0
Synopsis
- newtype PackageVersion where
- UnsafePackageVersion {
- unPackageVersion :: [Int]
- pattern MkPackageVersion :: [Int] -> PackageVersion
- UnsafePackageVersion {
- data ValidationError
- = VTooShortErr [Int]
- | VNegativeErr Int
- data ReadStringError
- data ReadFileError
- mkPackageVersion :: [Int] -> Either ValidationError PackageVersion
- toText :: PackageVersion -> Text
Documentation
newtype PackageVersion Source #
PackageVersion
represents PVP version
numbers. It is similar to Data.Version's Version
(i.e. wraps a
[
) except:Int
]
PackageVersion
has noversionTags
.- We enforce PVP's "tags must be at least A.B" invariant via the smart-constructor pattern.
- Trailing zeroes are ignored in
Eq
,Ord
,Semigroup
, andMonoid
.
That is, we declare an equivalence class up to trailing zeroes.
In particular, the Monoid
identity is
[0] = { [0,0], [0,0,0], ... }
and its Semigroup
instance takes the greatest version (based on Ord
).
Note: Because we export the underlying list in various ways,
(e.g. show
), Eq
's extensionality law,
x == y ==> f x == f y
can be broken. Take care that you do not rely on this law if you are
using its underlying [
(or Int
]String
) representation.
Examples
>>>
UnsafePackageVersion [0,0,0,0] == UnsafePackageVersion [0,0,0]
True
>>>
UnsafePackageVersion [4,0,0] > UnsafePackageVersion [1,2,0,0]
True
>>>
UnsafePackageVersion [5,6,0] <> UnsafePackageVersion [9,0,0]
UnsafePackageVersion {unPackageVersion = [9,0,0]}
>>>
UnsafePackageVersion [0,9] <> UnsafePackageVersion [0,9,0,0]
UnsafePackageVersion {unPackageVersion = [0,9]}
>>>
TR.readEither @PackageVersion "UnsafePackageVersion {unPackageVersion = [3,2,1]}"
Right (UnsafePackageVersion {unPackageVersion = [3,2,1]})
>>>
TR.readEither @PackageVersion "UnsafePackageVersion {unPackageVersion = [3]}"
Left "Prelude.read: no parse"
Since: 0.1.0.0
UnsafePackageVersion | |
|
pattern MkPackageVersion :: [Int] -> PackageVersion | Since: 0.1.0.0 |
Instances
data ValidationError Source #
Errors that can occur when validating PVP version numbers.
Since: 0.1.0.0
VTooShortErr [Int] | PVP version numbers must be at least A.B Since: 0.1.0.0 |
VNegativeErr Int | PVP version numbers cannot be negative. Since: 0.1.0.0 |
Instances
data ReadStringError Source #
Errors that can occur when reading PVP version numbers.
Since: 0.1.0.0
RsReadStrErr String | Error when reading a string. Since: 0.1.0.0 |
RsValidateErr ValidationError | Validation error. Since: 0.1.0.0 |
Instances
data ReadFileError Source #
Errors that can occur when reading PVP version numbers from a file.
Since: 0.1.0.0
RfFileNotFoundErr String | Error for missing file. Since: 0.1.0.0 |
RfVersionNotFoundErr FilePath | Error for missing version. Since: 0.1.0.0 |
RfReadValidateErr ReadStringError | Read/Validation error. Since: 0.1.0.0 |
Instances
mkPackageVersion :: [Int] -> Either ValidationError PackageVersion Source #
Smart constructor for PackageVersion
. The length of the list must be
> 1 to match PVP's minimal A.B. Furthermore, all digits must be non-negative.
Examples
>>>
mkPackageVersion [1,2]
Right (UnsafePackageVersion {unPackageVersion = [1,2]})
>>>
mkPackageVersion [2,87,7,1]
Right (UnsafePackageVersion {unPackageVersion = [2,87,7,1]})
>>>
mkPackageVersion [1,2,-3,-4,5]
Left (VNegativeErr (-3))
>>>
mkPackageVersion [3]
Left (VTooShortErr [3])
>>>
mkPackageVersion []
Left (VTooShortErr [])
Since: 0.1.0.0
toText :: PackageVersion -> Text Source #
Displays PackageVersion
in Text
format.
Examples
>>>
toText (UnsafePackageVersion [2,7,10,0])
"2.7.10.0"
Since: 0.1.0.0