One should think that this is a FAQ, but I haven't been able to find an answer to this simple question:
Which version of a certain package do I have in my GHC installation?
I'm trying to learn Haskell, and in order to do that, I'm making my way through Real World Haskell. I've now reached chapter 11, which, among other topics, introduces QuickCheck.
Unfortunately, QuickCheck has changed since the book was published in 2009, and it seems it has undergone various revisions. Whenever I search for a new way of doing things, as alternatives to the instructions in the book, the new ways sometimes don't work either. Perhaps the 'new way' was described in 2012, but then QuickCheck changed yet again between then and now.
Ultimately, I'll have to figure out how to use QuickCheck from either the documentation or the source code, but it'd be tremendously helpful to know which version I ought to investigate.
I've not yet reached the point where I've learned about Cabal and such, so my question is grounded in sheer ignorance. Hopefully, there's an easy answer.
I use GHC on Windows, and apparently, QuickCheck is already bundled into my installation. I already have QuickCheck, but I don't know which version.
cabal info
You can use cabal info <packagename>
to get information about the package, including the currently installed version:
$ cabal info QuickCheck * QuickCheck (library) Synopsis: Automatic testing of Haskell programs Versions available: 1.1.0.0, 1.2.0.0, 1.2.0.1, 2.6, 2.7.4, 2.7.5, 2.7.6, 2.8, 2.8.1 (and 24 others) Versions installed: 2.8.1 Homepage: https://github.com/nick8325/quickcheck Bug reports: mailto:quickcheck@projects.haskell.org Description: QuickCheck is a library for random testing of program properties. The programmer provides a specification of the program, in the form of properties which functions should satisfy, and ...
So all you have to do is to grep
the "Versions installed":
$ cabal info QuickCheck | grep "Versions installed"
Versions installed: 2.8.1
On Windows, you can use findstr:
$ cabal info QuickCheck | findstr /C:"Versions installed"
Versions installed: 2.8.1
Remark: If you don't have <packagename>
installed but still want to know some information about it, you might need to cabal update
first.
ghc-pkg
If you don't have cabal
installed, you can still use GHC's package manager, ghc-pkg
:
$ ghc-pkg list QuickCheck
C:\Program Files\MinGHC-7.8.4\ghc-7.8.4\lib\package.conf.d:
QuickCheck-2.8.1
However, note that ghc-pkg
won't acknowledge cabal sandboxes:
$ cabal sandbox init
$ cabal install QuickCheck
$ ghc-pkg list QuickCheck
C:\Program Files\MinGHC-7.8.4\ghc-7.8.4\lib\package.conf.d:
(no packages)
In this case, you need to use ghc-pkg -f .\.cabal-sandbox\<platform>-packages.conf.d
or cabal exec
:
$ ghc-pkg -f .\.cabal-sandbox\x86_64-windows-ghc-7.8.4-packages.conf.d list QuickCheck
.\.cabal-sandbox\x86_64-windows-ghc-7.8.4-packages.conf.d:
QuickCheck-2.8.1
$ cabal exec -- ghc-pkg list QuickCheck
.\.cabal-sandbox\x86_64-windows-ghc-7.8.4-packages.conf.d:
QuickCheck-2.8.1
However, since you're already using cabal
, you can simply use cabal info
.