Which package version do I have?
Asked Answered
A

3

14

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.

Aerophobia answered 25/11, 2015 at 10:29 Comment(3)
This may help: #2893086Calci
*sigh*, another one for the list.Boost
@Calci That doesn't seem useful for a library that's already installed (and which, like most libraries, does not expose its Paths_* module).Kendre
B
13

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:[email protected]
    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.

Boost answered 25/11, 2015 at 10:57 Comment(1)
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.Kendre
P
5

Using Stack:

stack exec -- ghc-pkg list

Example:

% stack exec -- ghc-pkg list | grep aeson
aeson-0.11.3.0
aeson-pretty-0.8.8
Pleasant answered 27/7, 2021 at 16:11 Comment(1)
These days, I usually use stack ls dependencies.Aerophobia
H
3

If you're working inside ghci, you can use :show packages:

λ> :show packages
active package flags:
  -package-id base-4.13.0.0
Hoard answered 11/5, 2022 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.