I'm experiencing a type error when I run the following code:
runPost :: IO String
runPost = do
res <- post "http://httpbin.org/post" ["num" := (31337 :: Int)]
return $ show res
The error is the following:
• Couldn't match expected type ‘GHC.Exts.Item a0’
with actual type ‘FormParam’
The type variable ‘a0’ is ambiguous
• In the expression: "num" := (31337 :: Int)
In the second argument of ‘post’, namely
‘["num" := (31337 :: Int)]’
In a stmt of a 'do' block:
res <- post "http://httpbin.org/post" ["num" := (31337 :: Int)]
When I inspect the type of :=
in ghci, I see what appears to be the correct type:
*Main Network.Wreq> :t (:=)
(:=)
:: FormValue v =>
Data.ByteString.Internal.ByteString -> v -> FormParam
What I'm wondering is why GHC.Exts.Item
is appearing as the expect type when I run the compiler. I've only imported the functions I'm using from Network.Wreq
. Any ideas what might be going on here?
It's clear (to the compiler, if not to your fellow human) that
("num" := (31337 :: Int)) :: FormParam
. What isn't clear to the compiler (and which you need to help it decide on) is the type of[x]
oncex
is known to be aFormParam
.The
Item
"type" is actually a type family, coming from theIsList
class; and theIsList
connection is coming from having theOverloadedLists
extension turned on.