Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which package version do I have?

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.

like image 566
Mark Seemann Avatar asked Nov 25 '15 10:11

Mark Seemann


2 Answers

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.

like image 134
Zeta Avatar answered Nov 03 '22 22:11

Zeta


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
like image 31
Janus Troelsen Avatar answered Nov 03 '22 21:11

Janus Troelsen