versions
Types and parsers for software version numbers.
https://github.com/fosskers/versions
| Version on this page: | 4.0.2 | 
| LTS Haskell 24.18: | 6.0.8 | 
| Stackage Nightly 2025-11-04: | 6.0.8 | 
| Latest on Hackage: | 6.0.8 | 
versions-4.0.2@sha256:f68d8fd349e1543b1722df20569d25560f480116d22f8248c58c70e3b56046c4,1936Module documentation for 4.0.2
- Data
 
versions
A Haskell library for parsing and comparing software version numbers.
About
We like to give version numbers to our software in a myriad of ways. Some ways follow strict guidelines for incrementing and comparison. Some follow conventional wisdom and are generally self-consistent. Some are just plain asinine. This library provides a means of parsing and comparing any style of versioning, be it a nice Semantic Version like this:
1.2.3-r1+git123
…or a monstrosity like this:
2:10.2+0.0093r3+1-1
Please switch to Semantic Versioning if you aren’t currently using it. It provides consistency in version incrementing and has the best constraints on comparisons.
Usage
In general, versioning is the function you want. It attempts to parse a given
Text using the three individual parsers, semver, version and mess. If
one fails, it tries the next. If you know you only want to parse one
specific version type, use that parser directly (e.g. semver).
Lenses and Traversals
The parse result types have Lenses/Traversals for accessing their data fields. For instance, to increment the patch number of a parsed SemVer, you could:
incPatch :: SemVer -> SemVer
incPatch s = s & patch %~ (+ 1)
Or, something more involved:
-- | Get all major versions of legally parsed SemVers.
majors :: [Text] -> [Word]
majors vs = vs ^.. each . to semver . _Right . major
The to semver . _Right is clunky, so we provide some direct Text
Traverals inspired by
(micro)
lens-aeson:
-- | Get the major version of any `Text` that has one.
majors :: [Text] -> [Word]
majors vs = vs ^.. each . major
We can also use these Text Traversals to increment versions, as above:
incPatch :: Text -> Text
incPatch s = s & patch %~ (+ 1)
> incPatch "1.2.3"
"1.2.4"
Changes
Changelog
4.0.2 (2021-01-23)
Fixed
- A bug in zero parsing within SemVer prereleases. #42
 
4.0.1 (2020-10-22)
Fixed
- An infinite loop in 
Versioncomparison. aura#652 
4.0.0 (2020-10-20)
Changed
- Breaking: 
VChunknow cannot be empty. - Breaking: A 
Versionnow guaranteesNonEmptychunks. - Breaking: A 
Messnow guaranteesNonEmptychunks, and its structure has been significantly changed. Particularly,Messvalues are now aware of theIntvalues they hold (when they do), as well as “revision” values of the patternrXYZ. - Comparison of 
Versionvalues is more memory efficient. 
Added
Versionnow has an extra field,_vMeta :: [VChunk]for capturing “metadata” like Semver. This prevents otherwise nice-looking versions from being demoted toMess.- The 
MChunktype to accomodate the changes toMessmentioned above. 
Removed
- Breaking: 
Versionno longer has aMonoidinstance. 
Fixed
""no longer parses in any way. #32- Version strings with trailing whitespace no longer parse via 
versioning. #33 - Particular edge cases involving 
Messcomparisons. aura#646 - A particular edge case involving prereleases in 
Versioncomparisons. aura#586 
3.5.4 (2020-05-12)
Added
- The functions 
isIdeal,isGeneral, andisComplexforBool-based inspection of parse results. messMajor,messMinor,messPatch, andmessPatchChunkfor improved introspection intoMessvalues.
Changed
- Improved 
Messcomparison logic. 
3.5.3
- GHC 8.10 support.
 
3.5.2
- Added a new 
PVPtype and parsers. 
3.5.1.1
- GHC 8.8 compatibility.
 
3.5.0
- Updated to 
megaparsec-7. OurParsingErrortype alias has changed to match Megaparsec’s new error model, anderrorBundlePrettyis now exposed instead of the oldparseErrorPretty. 
3.4.0.1
- Enhanced the whitespace handling in 
semver',version', andmess'. 
3.4.0
- Removed 
ParseVand surrounding machinery. Useversioningnow instead of theparseVfunction. 
3.3.2
- GHC 8.4.1 compatibility.
 
3.3.0
- New 
Semantictypeclass that provides Traversals for SemVer-like data out of all the version types.Textwas also given an instance, so its much easier to manipulate directly: 
λ "1.2.3" & minor %~ (+ 1)
"1.3.3"
Some Lenses and Traversals had their names changed or were removed entirely to accomodate this new typeclass.
SemVerandVersionshould never contain negative values, so their numeric components were changed fromInttoWord.
3.2.0
- Updated for 
megaparsec-6and GHC 8.2. 
3.1.1
- Added instances for common typeclasses: 
Generic,NFData, andHashable. This is to avoid having users define these instances themselves as orphans. If there are more instances you want added, please let me know.Datawas left out on purpose. 
3.1.0
- Added support for epoch numbers in the 
Versiontype. These are numbers like the1:in1:2.3.4. These are used in Arch Linux in rare cases where packages change their versioning scheme, but need a reliable integer prefix to establish ordering. TheVersiontype has been given a new field,_vEpoch :: Maybe Int, and a corresponding lens,vEpoch. 
3.0.2
- Expose internal parsers so that they could be used in other parser programs that parse version numbers in larger files.
 
3.0.0
- Updated for 
megaparsec-5andghc-8 
2.0.0
- Switched to 
megaparsecto perform all parsing asText - Support for legacy 
Stringremoved - Added more Traversals and INLINE’d all Lenses/Traversals
 
1.1.0
- Added Lenses and Traversals (no 
lensdependency)