简体   繁体   中英

how do I install `Test.QuickCheck` GHCi can't find it, import fails

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.

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 (ie 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> -- ^_^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM