如何在Network.HTTP.Client中使用Data.Default(How to use Data.Default with Network.HTTP.Client)

编程入门 行业动态 更新时间:2024-10-24 10:26:56
如何在Network.HTTP.Client中使用Data.Default(How to use Data.Default with Network.HTTP.Client)

aws包使用默认请求的实例(在Aws / Core.hs中)。 在构建程序包期间,编译器会抱怨与下面相同的错误。

这是一个简单的事情,以同样的方式失败:

{-# LANGUAGE OverloadedStrings #-} import Data.Default (def) import Network.HTTP.Client (host) main :: IO () main = do print $ def { host = "http://foobar.com" }

编译器抱怨:

No instance for (Data.Default.Default http-client-0.3.8.2:Network.HTTP.Client.Types.Request) arising from a use of `def' Possible fix: add an instance declaration for (Data.Default.Default http-client-0.3.8.2:Network.HTTP.Client.Types.Request)

但我可以看到实例是在http-client / Network / HTTP / Client / Request.hs中定义的:

instance Default Request where def = Request { host = "localhost" , port = 80 , secure = False ...

这来自“干净”的环境:

$ cd $ rm -Rf .cabal .ghc $ cabal install cabal cabal-install $ cabal install http-client-0.3.8.2

如何使用Default with Request? 或者更好的是我如何构建aws包?

编辑:输出ghc-pkg

$ ghc-pkg list /var/lib/ghc/package.conf.d Cabal-1.16.0 GLURaw-1.3.0.0 GLUT-2.4.0.0 HTTP-4000.2.8 HUnit-1.2.5.2 MonadCatchIO-mtl-0.3.0.5 OpenGL-2.8.0.0 OpenGLRaw-1.3.0.0 QuickCheck-2.6 X11-1.6.1.1 X11-xft-0.3.1 array-0.4.0.1 async-2.0.1.4 attoparsec-0.10.4.0 base-4.6.0.1 bin-package-db-0.0.0.0 binary-0.5.1.1 bytestring-0.10.0.2 case-insensitive-1.1.0.2 cgi-3001.1.8.3 containers-0.5.0.0 data-default-0.5.1 deepseq-1.3.0.1 directory-1.2.0.1 dlist-0.5 extensible-exceptions-0.1.1.4 fgl-5.4.2.4 filepath-1.3.0.1 ghc-7.6.3 ghc-prim-0.3.0.0 hashable-1.2.1.0 haskell-src-1.0.1.5 haskell2010-1.1.1.0 haskell98-2.0.0.2 hoopl-3.9.0.0 hpc-0.6.0.0 html-1.0.1.2 integer-gmp-0.5.0.0 mtl-2.1.2 network-2.4.1.2 old-locale-1.0.0.5 old-time-1.1.0.1 parallel-3.2.0.3 parsec-3.1.3 pretty-1.1.1.0 primitive-0.5.0.1 process-1.1.0.2 random-1.0.1.1 regex-base-0.93.2 regex-compat-0.95.1 regex-posix-0.95.2 rts-1.0 split-0.2.2 stm-2.4.2 syb-0.4.0 template-haskell-2.8.0.0 text-0.11.3.1 time-1.4.0.1 transformers-0.3.0.0 unix-2.6.0.1 unordered-containers-0.2.3.0 utf8-string-0.3.7 vector-0.10.0.1 xhtml-3000.2.1 xmonad-0.11 xmonad-contrib-0.11.2 zlib-0.5.4.1 /home/ben/.ghc/i386-linux-7.6.3/package.conf.d Cabal-1.20.0.2 asn1-encoding-0.8.1.3 asn1-parse-0.8.1 asn1-types-0.2.3 base64-bytestring-1.0.0.1 blaze-builder-0.3.3.4 byteable-0.1.1 cereal-0.4.0.1 cipher-aes-0.2.8 cipher-des-0.0.6 cipher-rc4-0.1.4 conduit-1.2.0.2 connection-0.2.3 cookie-0.4.1.3 cprng-aes-0.5.2 crypto-cipher-types-0.0.9 crypto-numbers-0.2.3 crypto-pubkey-0.2.4 crypto-pubkey-types-0.4.2.2 crypto-random-0.0.8 cryptohash-0.11.6 data-default-class-0.0.1 exceptions-0.6.1 http-client-0.4.0 http-client-tls-0.2.2 http-conduit-2.1.4.3 http-types-0.8.5 lifted-base-0.2.3.0 mime-types-0.1.0.4 mmorph-1.0.4 monad-control-0.3.3.0 nats-0.2 pem-0.2.2 publicsuffixlist-0.1 resourcet-1.1.2.3 securemem-0.1.3 semigroups-0.15.3 socks-0.5.4 streaming-commons-0.1.5 tls-1.2.9 transformers-base-0.4.3 void-0.6.1 x509-1.4.12 x509-store-1.4.4 x509-system-1.4.5 x509-validation-1.5.0

The aws package uses an instance of Default Request (in Aws/Core.hs). During the building of the package the compiler complains with the same error as below.

Here is something simple that fails the same way:

{-# LANGUAGE OverloadedStrings #-} import Data.Default (def) import Network.HTTP.Client (host) main :: IO () main = do print $ def { host = "http://foobar.com" }

The compiler complains:

No instance for (Data.Default.Default http-client-0.3.8.2:Network.HTTP.Client.Types.Request) arising from a use of `def' Possible fix: add an instance declaration for (Data.Default.Default http-client-0.3.8.2:Network.HTTP.Client.Types.Request)

But I can see that the instance is defined in http-client/Network/HTTP/Client/Request.hs:

instance Default Request where def = Request { host = "localhost" , port = 80 , secure = False ...

This is from a "clean" environment:

$ cd $ rm -Rf .cabal .ghc $ cabal install cabal cabal-install $ cabal install http-client-0.3.8.2

How can I use Default with Request? Or better yet how can I build the aws package?

Edit: Output of ghc-pkg

$ ghc-pkg list /var/lib/ghc/package.conf.d Cabal-1.16.0 GLURaw-1.3.0.0 GLUT-2.4.0.0 HTTP-4000.2.8 HUnit-1.2.5.2 MonadCatchIO-mtl-0.3.0.5 OpenGL-2.8.0.0 OpenGLRaw-1.3.0.0 QuickCheck-2.6 X11-1.6.1.1 X11-xft-0.3.1 array-0.4.0.1 async-2.0.1.4 attoparsec-0.10.4.0 base-4.6.0.1 bin-package-db-0.0.0.0 binary-0.5.1.1 bytestring-0.10.0.2 case-insensitive-1.1.0.2 cgi-3001.1.8.3 containers-0.5.0.0 data-default-0.5.1 deepseq-1.3.0.1 directory-1.2.0.1 dlist-0.5 extensible-exceptions-0.1.1.4 fgl-5.4.2.4 filepath-1.3.0.1 ghc-7.6.3 ghc-prim-0.3.0.0 hashable-1.2.1.0 haskell-src-1.0.1.5 haskell2010-1.1.1.0 haskell98-2.0.0.2 hoopl-3.9.0.0 hpc-0.6.0.0 html-1.0.1.2 integer-gmp-0.5.0.0 mtl-2.1.2 network-2.4.1.2 old-locale-1.0.0.5 old-time-1.1.0.1 parallel-3.2.0.3 parsec-3.1.3 pretty-1.1.1.0 primitive-0.5.0.1 process-1.1.0.2 random-1.0.1.1 regex-base-0.93.2 regex-compat-0.95.1 regex-posix-0.95.2 rts-1.0 split-0.2.2 stm-2.4.2 syb-0.4.0 template-haskell-2.8.0.0 text-0.11.3.1 time-1.4.0.1 transformers-0.3.0.0 unix-2.6.0.1 unordered-containers-0.2.3.0 utf8-string-0.3.7 vector-0.10.0.1 xhtml-3000.2.1 xmonad-0.11 xmonad-contrib-0.11.2 zlib-0.5.4.1 /home/ben/.ghc/i386-linux-7.6.3/package.conf.d Cabal-1.20.0.2 asn1-encoding-0.8.1.3 asn1-parse-0.8.1 asn1-types-0.2.3 base64-bytestring-1.0.0.1 blaze-builder-0.3.3.4 byteable-0.1.1 cereal-0.4.0.1 cipher-aes-0.2.8 cipher-des-0.0.6 cipher-rc4-0.1.4 conduit-1.2.0.2 connection-0.2.3 cookie-0.4.1.3 cprng-aes-0.5.2 crypto-cipher-types-0.0.9 crypto-numbers-0.2.3 crypto-pubkey-0.2.4 crypto-pubkey-types-0.4.2.2 crypto-random-0.0.8 cryptohash-0.11.6 data-default-class-0.0.1 exceptions-0.6.1 http-client-0.4.0 http-client-tls-0.2.2 http-conduit-2.1.4.3 http-types-0.8.5 lifted-base-0.2.3.0 mime-types-0.1.0.4 mmorph-1.0.4 monad-control-0.3.3.0 nats-0.2 pem-0.2.2 publicsuffixlist-0.1 resourcet-1.1.2.3 securemem-0.1.3 semigroups-0.15.3 socks-0.5.4 streaming-commons-0.1.5 tls-1.2.9 transformers-base-0.4.3 void-0.6.1 x509-1.4.12 x509-store-1.4.4 x509-system-1.4.5 x509-validation-1.5.0

最满意答案

我猜你安装了两个不同版本的data-default或data-default-class 。 Request是其中一个类的实例,而不是另一个类的实例。 不幸的是,这是一个非常常见的问题,你可以看到我在Reddit上提供的类似答案 。

I'm guessing you have two different versions of data-default or data-default-class installed. Request is an instance for one of those classes, but not the other. This is unfortunately a very common problem, you can see a similar answer I provided on Reddit.

更多推荐

本文发布于:2023-07-29 20:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319574.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Network   HTTP   Default   Data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!