8

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?

Background

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.

Zeta
  • 95,453
  • 12
  • 173
  • 214
Mark Seemann
  • 209,566
  • 41
  • 390
  • 671
  • This may help: http://stackoverflow.com/questions/2892586/how-can-my-haskell-program-or-library-find-its-version-number – shree.pat18 Nov 25 '15 at 10:35
  • 3
    \*sigh\*, another one for [the list](http://stackoverflow.com/a/23733494/1139697). – Zeta Nov 25 '15 at 11:09
  • 2
    @shree.pat18 That doesn't seem useful for a library that's already installed (and which, like most libraries, does not expose its `Paths_*` module). – Daniel Wagner Nov 25 '15 at 14:43

1 Answers1

6

Using 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.

Using 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.

Zeta
  • 95,453
  • 12
  • 173
  • 214
  • 2
    Or, if you don't want to go through `cabal` (and are using `ghc`), you can `ghc-pkg list QuickCheck`, which by default will just show version numbers for installed packages. – Daniel Wagner Nov 25 '15 at 14:42