Getting your Version
The Paths_foo has your version, but beware
This just a brief note to self, and y’all, on how an app can discover its own version.
Often it is useful to be able to expose your version, possibly in response to
--version request from the command line. Clearly it is desirable that this should not rely on manual intervention, leaving two options:
the Haskell build system makes it available somehow or
the versions get burned into the source as part of the project’s release mechanism.
For smaller projects the first variant is particularly welcome as they are unlikely to have the kind of release mechanism that can ensure the version is reliable made available to the running program.
Yay, the Toolchain has your back, mostly
If your app is called
foo then it will be found in the
Paths_foo module automagically maintained by the build system. (The
Paths_foo module is documented in the Cabal section of past GHC doc sets.)
If you need to use the version in an executable then it will have to list
foo in its Cabal dependencies.
The recipe I use
Paths_foo to the library’s exposed modules
You can just list
Paths_foo in the
other-modules: of your executable but then
ghci will not be able to follow along.
If you don’t need
ghci to see the
Paths_foo then your generated cabal file should always have
Paths_foo listed in
other-modules and you just can import it. If you need ghci to see it will have to be listed in the library’s
Got an issue with any of this? Please share or drop me a line (see below).