I am trying to retrieve a response from an endpoint using the req Haskell package.
I understand that I need to use a type annotation to specify what 'a0' should be but I'm not sure what 'a0' is referring to and what type I should give it.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.IO.Class
import Data.Aeson
import Network.HTTP.Req
main :: IO ()
main = runReq defaultHttpConfig $ do
r <- req GET
(https "google.com")
NoReqBody
jsonResponse
mempty
liftIO $ print jsonResponse
Full traceback:
/Users/timothy/repos/uptime-bot/app/Main.hs:10:14: error:
• Ambiguous type variable ‘a0’ arising from a use of ‘req’
prevents the constraint ‘(FromJSON a0)’ from being solved.
Probable fix: use a type annotation to specify what ‘a0’ should be.
These potential instances exist:
instance FromJSON DotNetTime
-- Defined in ‘aeson-1.4.5.0:Data.Aeson.Types.FromJSON’
instance FromJSON Value
-- Defined in ‘aeson-1.4.5.0:Data.Aeson.Types.FromJSON’
instance (FromJSON a, FromJSON b) => FromJSON (Either a b)
-- Defined in ‘aeson-1.4.5.0:Data.Aeson.Types.FromJSON’
...plus 25 others
...plus 63 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block:
r <- req GET (https "google.com") NoReqBody jsonResponse mempty
In the second argument of ‘($)’, namely
‘do r <- req GET (https "google.com") NoReqBody jsonResponse mempty
liftIO $ print jsonResponse’
In the expression:
runReq defaultHttpConfig
$ do r <- req
GET (https "google.com") NoReqBody jsonResponse mempty
liftIO $ print jsonResponse
|
10 | r <- req GET
| ^^^^^^^^...
Fixed it like this: