what's the difference between Test.QuickCheck and Test.Tasty.QuickCheck? - haskell

I am new to Quickcheck, and in my program,
import Test.QuickCheck works, but
import Test.Tasty.QuickCheck will report "Could not find module ‘Test.Tasty’"

In case you are using stack, you need to build that package:
stack build tasty
stack build tasty-quickcheck
After that, stack ghc ... and stack ghci will be able to find the module Test.Tasty.QuickCheck.

Related

How import modules in haskell

I'm trying to use this module in my haskell code: (http://hackage.haskell.org/package/MissingH-1.0.0/docs/Data-String-Utils.html) to use the function "replace" - However, when I try this code:
import Data.String.Utils
Haskell tells me there is no such module.
I've installed cabal and stack to do stack build and cabal build

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

How to load everything from Haskell module in GHCi

I would like to import hidden data constructor from a module being in GHCi. It looks like it is not possible for packages.
For source files :l is working
stack ghc --package ghc
:set -XStandaloneDeriving
import Module
-- ModuleName is not exposed
deriving instance Show ModuleName -- fails
Update 1. I found an article to call hidden functions but it is not exactly I was looking. Probably TH can do more.

Cannot find module 'Text.HTML.TagSoup'

I have installed tagsoup with
cabal v1-install tagsoup
and verified the install with ghc-pkg list | grep tagsoup
However, in my very simple Haskell 8.6.5 program the statement
import Text.HTML.TagSoup
fails with cannot find module 'Text.HTML.TagSoup'
ghc -v is not useful
cabal new-install tagsoup fails with a ton of errors
import Network.HTTP.Conduit
import Text.HTML.TagSoup
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Lazy.Char8 as CL
main :: IO ()
main = do
lbs <- simpleHttp "https://wiki.haskell.org"
print $ show lbs
-- tagsoup code removed
For this kind of a single file use case, I'd recommend using a Stack script. If you add the following two lines to the top of your file:
#!/usr/bin/env stack
-- stack --resolver lts-13.27 script
You can then run stack filename.hs, which will:
Download GHC if necessary
Download and build all dependencies, based on your import list
Use runghc to run your program
More information:
How to Script
Get Started with Haskell

Trying to install System.Random on stack

I'm using stack 1.6.1. In src/Main.hs I start with
module Main where
import System.IO
import System.Random
...
I do not use anything from System.Random at this time.
When I run stack ghci I get
/Users/mkaravan/end2end/Music/music/src/Main.hs:4:1: error:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
|
4 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
I've had no luck with any of the following commands:
stack install System.Random
stack install system.random
stack install random
I get this error:
>>> stack install System.Random
Error parsing targets: Directory not found: System.Random
How do I get System.Random to run in Stack?
You probably need to add random to the dependencies section in your package.yaml (or if you are not using hpack, to build-depends in *.cabal). This tells stack that the package depends on the random package, which contains the System.Random module.
Probably the most straightforward command is stack ghci --package random. But in theory stack install random should have worked as well. However, since you haven't included the output from that call, it's not clear what didn't work with it.

Resources