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

2024-03-25

我正在尝试这个简单的例子:

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

我从这里尝试过:Haskell:找不到模块“Network.HTTP” https://stackoverflow.com/questions/58754127/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

当你使用stack项目你应该首先添加依赖项 https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies in dependencies您的部分package.yaml像那样:

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

然后运行stack build.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐