Could not find module `Network.HTTP’ on simple http get example

Total
1
Shares

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

Solution

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.

Leave a Reply

Your email address will not be published. Required fields are marked *