Haskell JSON问题

时间:2015-04-22 11:14:42

标签: json haskell bytestring aeson

一直试图让这段代码正常工作,但是编译器却抛出了一个错误?

 {-# LANGUAGE OverloadedStrings, DeriveGeneric #-}

 import Data.Aeson
 import Data.Text
 import Control.Applicative
 import Control.Monad
 import qualified Data.ByteString.Lazy as B
 import Network.HTTP.Conduit (simpleHttp)
 import GHC.Generics


data Temperatures =
Temperatures { date  :: String
     , temperature   :: Int
     } deriving (Show,Generic)


instance FromJSON Temperatures
instance ToJSON Temperatures

jsonURL :: String
jsonURL = "A JSON URL"

getJSON :: IO B.ByteString
getJSON = simpleHttp jsonURL

main :: IO ()
main = do
d <- (eitherDecode <$> getJSON) :: IO (Either String [Temperatures])
case d of
Left err -> putStrLn err
Right ps -> print ps

我得到的错误信息是

Main.hs:25:11:
Couldn't match type `bytestring-      0.10.0.2:Data.ByteString.Lazy.Internal.ByteString'
              with `B.ByteString'
Expected type: IO B.ByteString
  Actual type: IO
                 bytestring-0.10.0.2:Data.ByteString.Lazy.Internal.ByteString
In the return type of a call of `simpleHttp'
In the expression: simpleHttp jsonURL
In an equation for `getJSON': getJSON = simpleHttp jsonURL

对于导致此错误的原因以及如何解决此问题的任何建议都将非常感激。感谢。

0 个答案:

没有答案