{-# LANGUAGE OverloadedStrings #-}
import Network.Wreq
import Data.ByteString.Lazy
import Control.Lens
totalResponse :: IO (Response ByteString)
totalResponse = response
status :: Status
status = response ^. responseStatus
response = get "url"
which gives
getRequest.hs:10:23: error:
• Couldn't match type ‘Response body0’
with ‘IO (Response ByteString)’
Expected type: Getting Status (IO (Response ByteString)) Status
Actual type: (Status -> Const Status Status)
-> Response body0 -> Const Status (Response body0)
• In the second argument of ‘(^.)’, namely ‘responseStatus’
In the expression: response ^. responseStatus
In an equation for ‘status’: status = response ^. responseStatus
when I look for
:type response ^. responseStatus
in ghci
it gives
response ^. responseStatus :: Status
I'm completely new to Haskell.
As the comments above pointed out, it is probably a good idea to learn Haskell before using more complex libraries. As stated, you have a type mismatch in your code.
response
is not a value as you might think, but a monad. If you want to get the status code of your response you could try this:Note that everything is done inside the IO monad, which is the way Haskell has to deal with IO side-effects.