Trying to install System.Random on stack - haskell

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.

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

Haskell Language Server in VS code shows 'could not find module' Error

I have the following imports in my file
import Control.Applicative (Applicative(liftA2))
import Control.Monad ( guard )
import qualified Data.Vector as V
and I get the error that reads could not find module 'Data.Vector'
The module is installed. I have vector in dependencies and the program builds fine. I just can't get rid of the error in VS Code.
What extra installations do I have to do to fix this?
I have tried:
cabal install vector --lib
Have you tried?
cabal install vector --lib

GHCi can't load script that imports `Data.Set` or `Data.Maybe` if external package is imported

I have a script
#!/usr/bin/env stack
{-# LANGUAGE QuasiQuotes #-}
module Script where
import qualified Data.Set as Set (Set, fromList)
import Data.Maybe (fromJust)
{- import Text.RawString.QQ not neccessary for demonstration -}
main :: IO()
main = print "foo"
That I run with stack --resolver lts-12.5 runghc --package raw-strings-qq Script.hs
But I can't load it in GHCi:
$ stack ghci --resolver lts-12.5 --package raw-strings-qq
Note: No local targets specified, so a plain ghci will be started with no package hiding or package options.
If you want to use package hiding and options, then you can try one of the following:
* If you want to start a different project configuration than /home/t/.stack/global-project/stack.yaml, then you can use stack init to create a new
stack.yaml for the packages in the current directory.
* If you want to use the project configuration at /home/t/.stack/global-project/stack.yaml, then you can add to its 'packages' field.
Configuring GHCi with the following packages:
GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help
Loaded GHCi configuration from /tmp/haskell-stack-ghci/2a3bbd58/ghci-script
Prelude> :load Script.hs
[1 of 1] Compiling Script ( Script.hs, interpreted )
Stacko.hs:7:1: error:
Could not find module ‘Data.Set’
Perhaps you meant Data.Int (from base-4.11.1.0)
Use -v to see a list of the files searched for.
|
7 | import qualified Data.Set as Set (Set, fromList)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Own research:
I can load the file if I start ghci with just stack ghci --resolver lts-12.5.
Interestingly, when I import Data.Set 'unqualified' as I do with Data.Maybe:
import Data.Set
import Data.Maybe
the error persists, but when I drop the Data.Set import all together I can load Script.hs
Imports that don't work: Data.Set, Data.Map.Strict
Imports that work: Data.List, Data.Function, Data.Maybe
packages that produce the error: raw-strings-qq, HUnit

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

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

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.

Resources