Reputation:
been trying to get this code working but the compiler is throwing out an error?
{-# 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
And the error message i'm getting is
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
Any suggestions of what's causing this error and how to fix it would be much appreciated. Thanks.
Upvotes: 2
Views: 149
Reputation: 922
Ah. This is known as Cabal Hell. Fixing it is an active area of research in the Haskell community. My suggestions would be as follows:
If you're using Windows:
C:\Users\blauwers\AppData\Roaming\cabal
and was just called config
.remote-repo
. In my case that was only remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
.If you're using Linux: I don't know where the global cabal config file is, but the process is the same.
Upvotes: 0
Reputation: 131
It looks like there are multiple versions of the bytestring package installed. You can use the following command to find the bytestring packages:
ghc-pkg list bytestring
If there are more than one installed then the following could solve the problem:
ghc-pkg unregister
Or,
build with ghc --make --hide-package
Upvotes: 2