How import modules in haskell - 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

Related

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

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.

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.

Haskell Import MissingH

I'm trying to import the Data.String.Utils module in my Haskell code, this is part of the MissingH package. I've installed cabal and used it to acquire MissingH, which is properly installed. However, wehn I try adding
import Data.String.Utils
to my code, WinHugs returns
ERROR file:.\ex.hs - Can't find imported module "Data.String.Utils"
Any feedback?
You already have MissingH installed with Cabal.
Using Cabal packages with WinHugs is hit and miss.
Use ghci and import Data.String.Utils should work.

Resources