Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

haskell

ghc

cabal

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
like image 638
Guerlando OCs Avatar asked Jan 23 '26 19:01

Guerlando OCs


1 Answers

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.

like image 198
aleksxor Avatar answered Jan 25 '26 21:01

aleksxor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!