在简单的 http get 示例中找不到模块“Network.HTTP”

Could not find module `Network.HTTP' on simple http get 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

我明白了

/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
  | ^^^^^^^^^^^^^^^^^^^

我从这里试过:

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

当您使用 stack 项目时,您应该首先在 package.yamldependencies 部分中 add dependency 像这样:

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

然后 运行 stack build.