gpt4 book ai didi

haskell - WReq 简单发布请求 - 由于使用 ‘:=’ 而导致 (FormValue v0) 没有实例错误

转载 作者:行者123 更新时间:2023-12-05 06:42:09 26 4
gpt4 key购买 nike

我正在尝试编写一些代码来对 json API 执行一些请求。我有这个功能:

apiLogin = do
r <- post "https://url:port/somewhere" ["user" := "some_name", "password" := "test"]
putStrLn $ cs $ r ^. responseBody

这是我遇到的错误:

Api.hs:12:96:
No instance for (FormValue v0) arising from a use of ‘:=’
The type variable ‘v0’ is ambiguous
Note: there are several potential instances:
instance FormValue a => FormValue (Maybe a)
-- Defined in ‘Network.Wreq.Types’
instance FormValue GHC.Int.Int16 -- Defined in ‘Network.Wreq.Types’
instance FormValue GHC.Int.Int32 -- Defined in ‘Network.Wreq.Types’
...plus 18 others
In the expression: "user" := "some_name"
In the second argument of ‘post’, namely
‘["user" := "some_name", "password" := "test"]’
In a stmt of a 'do' block:
r <- post
"https://url:port/somewhere/g"
["user" := "some_name", "password" := "test"]

Api.hs:12:99:
No instance for (Data.String.IsString v0)
arising from the literal ‘"some_name"’
The type variable ‘v0’ is ambiguous
Note: there are several potential instances:
instance Data.String.IsString
http-client-0.4.29:Network.HTTP.Client.Types.Request
-- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Request’
instance Data.String.IsString
http-client-0.4.29:Network.HTTP.Client.Types.RequestBody
-- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Types’
instance (a ~ Data.ByteString.Internal.ByteString) =>
Data.String.IsString
(attoparsec-0.13.0.2:Data.Attoparsec.ByteString.Internal.Parser a)
-- Defined in ‘Data.Attoparsec.ByteString.Char8’
...plus 11 others
In the second argument of ‘(:=)’, namely ‘"some_name"’
In the expression: "user" := "some_name"
In the second argument of ‘post’, namely
‘["user" := "some_name", "password" := "test"]’

Api.hs:12:122:
No instance for (FormValue v1) arising from a use of ‘:=’
The type variable ‘v1’ is ambiguous
Note: there are several potential instances:
instance FormValue a => FormValue (Maybe a)
-- Defined in ‘Network.Wreq.Types’
instance FormValue GHC.Int.Int16 -- Defined in ‘Network.Wreq.Types’
instance FormValue GHC.Int.Int32 -- Defined in ‘Network.Wreq.Types’
...plus 18 others
In the expression: "password" := "test"
In the second argument of ‘post’, namely
‘["user" := "some_name", "password" := "test"]’
In a stmt of a 'do' block:
r <- post
"https://url:port/somewhere/g"
["user" := "some_name", "password" := "test"]

Api.hs:12:125:
No instance for (Data.String.IsString v1)
arising from the literal ‘"test"’
The type variable ‘v1’ is ambiguous
Note: there are several potential instances:
instance Data.String.IsString
http-client-0.4.29:Network.HTTP.Client.Types.Request
-- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Request’
instance Data.String.IsString
http-client-0.4.29:Network.HTTP.Client.Types.RequestBody
-- Defined in ‘http-client-0.4.29:Network.HTTP.Client.Types’
instance (a ~ Data.ByteString.Internal.ByteString) =>
Data.String.IsString
(attoparsec-0.13.0.2:Data.Attoparsec.ByteString.Internal.Parser a)
-- Defined in ‘Data.Attoparsec.ByteString.Char8’
...plus 11 others
In the second argument of ‘(:=)’, namely ‘"test"’
In the expression: "password" := "test"
In the second argument of ‘post’, namely
‘["user" := "some_name", "password" := "test"]’

我不知道我做错了什么,我正在尝试做他们在文档中显示的相同内容(http://www.serpentine.com/wreq/tutorial.html 通过邮寄上传数据)除了在 ghci 中没有。我正在使用重载的字符串。有人可以解释这些错误的含义吗?

最佳答案

错误是因为函数 := 不明确。如果指定名称和值都是 ByteString,代码将运行。

不过,我不确定为什么它可以解决 GHCI 中的歧义,但不能解决独立代码中的歧义。

关于haskell - WReq 简单发布请求 - 由于使用 ‘:=’ 而导致 (FormValue v0) 没有实例错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com