0

I am getting this error:

No instance for (Show (ClientM Bittrex)) arising from a use of ‘print

While building the following code:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}

module Main where

import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.HTTP.Client (newManager, defaultManagerSettings)
import Servant.API
import Servant.Client

data Bittrex = Bittrex
  { success :: Bool,
    message :: String,
    result :: Inner
  } deriving (Generic, Show)

instance FromJSON Bittrex
instance ToJSON Bittrex

data Inner = Inner
  { bid :: Float,
    ask :: Float,
    last :: Float
  } deriving (Generic, Show)

instance FromJSON Inner
instance ToJSON Inner

--------------------------------------------------------------------------------

-- https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC

type BittrexAPI = "api" :> "v1.1" :> "public" :> "getticker?market=BTC-LTC" :> Get '[JSON] Bittrex

-----------------------------------------------------------------------------
bittrexAPI :: Proxy BittrexAPI
bittrexAPI = Proxy

bittrex = client bittrexAPI

main :: IO ()
main = do
  manager <- newManager defaultManagerSettings
  res <- runClientM bittrex (ClientEnv manager (BaseUrl Http "bittrex.com" 80 ""))
  case res of
    Left err -> putStrLn $ "Error: " ++ show err
    Right test -> do
        print $ bittrex

I know the problem is coming from the fact that I have a JSON response with embedded JSON. I'm not sure how to rectify this or more importantly why this is happening. The request link is https://bittrex.com/api/v1.1/public/getticker?market=BTC-LTC

Jim
  • 1
  • 4
  • The issue comes from the last line `do print $ bittrex` (which should just be `print bittrex`). You're trying to print the client generated by Servant (exactly what the error message is telling you), when I think you meant to print the api response `test :: Bittrex`. – cdk Oct 03 '17 at 17:42
  • Thank you, I had another data type (data Test = ...) that I removed from the code before putting it here. This confused me. Thank you for responding! – Jim Oct 03 '17 at 18:20

0 Answers0