Reputation: 983
I'm trying to code something to do a few requests to a json API. I have this function :
apiLogin = do
r <- post "https://url:port/somewhere" ["user" := "some_name", "password" := "test"]
putStrLn $ cs $ r ^. responseBody
Here are the errors I'm getting :
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"]’
I have no idea what I'm doing wrong, I'm trying to do the same thing they show in the doc (http://www.serpentine.com/wreq/tutorial.html uploading data via post) except not in ghci. I am using Overloaded strings. Could someone explain what those error means ?
Upvotes: 3
Views: 509
Reputation: 36385
The error is because of ambiguity against the function :=
. If you specify that both name and values are ByteString
, the code will run.
I'm not sure why it resolves ambiguity in GHCI but not in standalone code, though.
Upvotes: 1