Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Internal module. Exposes the invariant-breaking UnsafePackageVersion
constructor.
Since: 0.1.0.0
Synopsis
- newtype PackageVersion where
- UnsafePackageVersion [Int]
- pattern MkPackageVersion :: [Int] -> PackageVersion
- data ValidationError
- data ReadStringError
- data ReadFileError
- mkPackageVersion :: [Int] -> Either ValidationError PackageVersion
- unPackageVersion :: PackageVersion -> [Int]
- toText :: PackageVersion -> Text
- prettyString :: Pretty a => a -> String
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" 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,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 [9,0,0]
>>>
UnsafePackageVersion [0,9] <> UnsafePackageVersion [0,9,0,0]
UnsafePackageVersion [0,9]
>>>
TR.readEither @PackageVersion "UnsafePackageVersion [3,2,1]"
Right (UnsafePackageVersion [3,2,1])
>>>
TR.readEither @PackageVersion "UnsafePackageVersion [-2]"
Left "Prelude.read: no parse"
>>>
TR.readEither @PackageVersion "UnsafePackageVersion []"
Left "Prelude.read: no parse"
Since: 0.1.0.0
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
ValidationErrorEmpty | PVP version number cannot be empty. Since: 0.3 |
ValidationErrorNegative Int | PVP version numbers cannot be negative. Since: 0.2 |
Instances
data ReadStringError Source #
Errors that can occur when reading PVP version numbers.
Since: 0.1.0.0
ReadStringErrorParse String | Error when parsing a string. Since: 0.2 |
ReadStringErrorValidate ValidationError | Validation error. Since: 0.2 |
Instances
data ReadFileError Source #
Errors that can occur when reading PVP version numbers from a file.
Since: 0.1.0.0
ReadFileErrorGeneral String | General error when reading a file. Since: 0.2 |
ReadFileErrorVersionNotFound FilePath | Error for missing version. Since: 0.2 |
ReadFileErrorReadString ReadStringError | Read/Validation error. Since: 0.2 |
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 [1,2])
>>>
mkPackageVersion [2,87,7,1]
Right (UnsafePackageVersion [2,87,7,1])
>>>
mkPackageVersion [1,2,-3,-4,5]
Left (ValidationErrorNegative (-3))
>>>
mkPackageVersion [3]
Right (UnsafePackageVersion [3])
>>>
mkPackageVersion []
Left ValidationErrorEmpty
Since: 0.1.0.0
unPackageVersion :: PackageVersion -> [Int] Source #
Since: 0.3
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
prettyString :: Pretty a => a -> String Source #
Renders a string via Pretty'
s smart option + default layout.
Since: 0.2