0
votes

I'm on macOS running stack/GHCi version 8.4.3:

import Test.QuickCheck fails at both the GHCi prompt and in my .hs files. Either way I'm told it's not found. GHCi Prelude>

<no location info>: error:
    Could not find module ‘Test.QuickCheck’
    It is not a module in the current program, or in any known package.

in .hs file >

"Could not find module ‘Test.QuickCheck’ ' 

The source code is on this page but I'm not sure how to install a new package into stack manually. From my brief reading when I googled "install Haskell package" it suggests installing a cabal package universally is a bad idea. Not sure this is a cabal package, and in any case it would be good to be able to import it for any project I think in my case.

1
You need to install the corresponding package with a package manager, for example cabal, so cabal install QuickCheck.Willem Van Onsem
Thanks, reading the cabal QuickStart guide this is amazingly not clear like that!wide_eyed_pupil
does the directory from which I issue the command matter to where it is installed? I want it in the central repository, although I'm not sure where cabal put that in the first place.wide_eyed_pupil
If you're using Stack, you can add packages to a GHCi session. For compiled code, you should create a Stack project with stack new and then add packages to the project configuration files. There's a few alternative ways to do this, so consult the documentation.Mark Seemann
cabal install QuickCheck is exactly the thing your "bad idea" link is warning against.Daniel Wagner

1 Answers

1
votes

The modern way to do this for a quick ghci session is to use cabal repl and add a dependency on QuickCheck:

% cabal repl --build-depends QuickCheck
> import Test.QuickCheck
Test.QuickCheck> -- ^_^

For longer-term programming (i.e. not just quick tests of stuff in ghci), the modern way is to create a cabal package and add QuickCheck to the build-depends section in the *.cabal produced:

% mkdir fancy-package
% cd fancy-package
% cabal init
<follow prompts>
% $EDITOR fancy-package.cabal
<find build-depends: and add, for example, QuickCheck ^>= 2.14 to the list>
% cabal repl
*Main> import Test.QuickCheck
*Main Test.QuickCheck> -- ^_^