3

I'm trying this simple example:

module Main where
import Network.HTTP

import Lib

get :: String -> IO String
get url = simpleHTTP (getRequest url) >>= getResponseBody

-- 2. Get the response code
getCode :: String -> IO ResponseCode
getCode url = simpleHTTP req >>= getResponseCode
    where req = getRequest url

main :: IO ()
main = do 
    x <- get "http://google.com"
    putStrLn x

I get

/workspaces/hask_exercises/api-exercises/app/Main.hs:2:1: error:
    Could not find module `Network.HTTP'
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
2 | import Network.HTTP
  | ^^^^^^^^^^^^^^^^^^^

I tried from here: Haskell: Could not find module ‘Network.HTTP’

cabal install --lib network
cabal: The program 'ghc' version >=7.0.1 is required but it could not be
found.


 ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.4
8
  • 1
    how did you install Haskell (GHC/Cabal)? How did you setup / compile your program? Commented May 26, 2021 at 4:10
  • which version of cabal are you using? Commented May 26, 2021 at 7:12
  • @lsmor cabal ` 3.4.0.0` Commented May 26, 2021 at 14:23
  • @Carsten sh -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh" and stack run Commented May 26, 2021 at 14:24
  • My guess is that GHC is not in you path (cabal does not find it) - you write you used stack - maybe you did stack setup? If it'll not install GHC in your path - and in this case you should use stack to install your dependencies too Commented May 26, 2021 at 14:49

1 Answer 1

4
+50

As you're using stack project you should first add dependency in dependencies section in your package.yaml like that:

dependencies:
- base >= 4.7 && < 5
- HTTP

and then run stack build.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.