微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

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

我从这里尝试: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 项目时,您应该首先在 dependenciespackage.yaml 部分中add dependency,如下所示:

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

然后运行 ​​stack build

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。