@hackage package-version0.4

A package for retrieving a package's version number.

Package Version

Hackage ci BSD-3-Clause

Package Description

This package defines a PackageVersion type that represents PVP version numbers. We provide functionality for reading these numbers from cabal files at both runtime and compile-time, the latter being useful when implementing --version options in executables. See the haddocks on hackage for more information.

Alternatives

Reading the cabal version can also be achieved by utilizing the generated Paths_<pkg-name> module. For instance, for a package named foo, we first add the generated module to our list of modules in foo.cabal:

cabal-version:      2.4
name:               foo
version:            0.1

...

library
  other-modules:   Paths_foo
  autogen-modules: Paths_foo

Then we can reference this in our code:

import Data.List (intercalate)
import Data.Version (Version(versionBranch))
import Paths_foo qualified as Paths

vsn :: String
vsn = intercalate "." $ fmap show $ versionBranch Paths.version

See the documentation for more details.