2
我试图编写一些东西来做一些json API的请求。 我有这样的功能:WReq简单的发布请求
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中的歧义问题,但不能解决独立代码中的歧义问题。 –
哈是的,谢谢!这就是它 – Ulrar
我有同样的问题,你在代码中做了什么修改来解决这个问题? – ManzMoody