Couldn't match expected type `http-client-0.6.4:Network.HTTP.Client.Types.ManagerSettings' with actual type `http-client-0.5.14:Network.HTTP.Client.Types.ManagerSettings'

I’m trying to compile a simple telegram api example;

{-# LANGUAGE OverloadedStrings #-}

import           Network.HTTP.Client      (newManager)
import           Network.HTTP.Client.TLS  (tlsManagerSettings)
import           Web.Telegram.API.Bot

main :: IO ()
main = do
  manager <- newManager tlsManagerSettings
  res <- getMe token manager
  case res of
    Left e -> do
      putStrLn "Request failed"
      print e
    Right Response { result = u } -> do
      putStrLn "Request succeded"
      print $ user_first_name u
  where token = Token "bot824086589:AAESEC1deeeMdTLLg7ga4AxqY3L8sK49J2s" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11

but I’m getting:

main.hs:11:25: error:
    * Couldn't match expected type `http-client-0.6.4:Network.HTTP.Client.Types.ManagerSettings'
                  with actual type `http-client-0.5.14:Network.HTTP.Client.Types.ManagerSettings'
      NB: `http-client-0.5.14:Network.HTTP.Client.Types.ManagerSettings'
            is defined in `Network.HTTP.Client.Types'
                in package `http-client-0.5.14'
          `http-client-0.6.4:Network.HTTP.Client.Types.ManagerSettings'
            is defined in `Network.HTTP.Client.Types'
                in package `http-client-0.6.4'
    * In the first argument of `newManager', namely
        `tlsManagerSettings'
      In a stmt of a 'do' block: manager <- newManager tlsManagerSettings
      In the expression:
        do { manager <- newManager tlsManagerSettings;
             res <- getMe token manager;
             case res of {
               Left e -> do { ... }
               Right (Response {result = u}) -> do { ... } } }

I think that the import isn’t specific so it imports the newest version of the library but it needs the old one. Is it possible for me to specify the version when importing? If not, then how can I delete the newest one? I don’t know how it got there, I simply did

cabal install telegram-api

I tried creating a cabal project, then:
Preprocessing executable ‘telegram-tests’ for telegram-tests-0.1.0.0…
[1 of 1] Compiling Main ( Main.hs, dist/build/telegram-tests/telegram-tests-tmp/Main.o )

Main.hs:3:1: error:
    Failed to load interface for `Network.HTTP.Client'
    It is a member of the hidden package `http-client-0.6.4'.
    Perhaps you need to add `http-client' to the build-depends in your .cabal file.
    It is a member of the hidden package `http-client-0.5.14'.
    Perhaps you need to add `http-client' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

Main.hs:4:1: error:
    Failed to load interface for `Network.HTTP.Client.TLS'
    It is a member of the hidden package `http-client-tls-0.3.5.3'.
    Perhaps you need to add `http-client-tls' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

then I did

  -- Other library packages from which modules are imported.
  build-depends:       base >=4.9 && <4.10,
                       telegram-api >= 0.7,
                       http-client >= 0.6.4,
                       http-client-tls >= 0.3.5.3

but I get

cabal run
./telegram-tests.cabal has been changed. Re-configuring with most recently
used options. If this fails, please run configure manually.
Resolving dependencies...
Warning: solver failed to find a solution:
Could not resolve dependencies:
trying: telegram-tests-0.1.0.0 (user goal)
next goal: http-client-tls (dependency of telegram-tests-0.1.0.0)
rejecting: http-client-tls-0.3.5.3/installed-KZY... (conflict: http-client-tls
=> http-client==0.5.14/installed-5k5..., telegram-tests => http-client>=0.6.4)
Dependency tree exhaustively searched.
Trying configure anyway.
Configuring telegram-tests-0.1.0.0...
cabal: Encountered missing dependencies:
http-client >=0.6.4, http-client-tls >=0.3.5.3

Ah it looks like telegram-api is somewhat old (2018), pinned to a number of old versions of libraries. I was going to suggest using stack to get around dependency headaches, but it wouldn’t solve the problem here.

How are you invoking cabal? Are you using new-build?

EDIT: Although it looks like the Github repo for telegram-api has been updated as recently as mid-2019: https://github.com/klappvisor/haskell-telegram-api

I dont know what new-build is, I just installed

haskell-platform

and I did

cabal init

So if the repo was updated then why I still get errors?

After going onto Hackage and staring at the bounds enough for the versions you’re trying to get, I figured it out. The version of http-client you’re asking for in your .cabal is too new. telegram-api wants something in the 0.5 range. If you lower that bound, it should compile.

thanks, it worked with

  -- Other library packages from which modules are imported.
  build-depends:       base >=4.9 && <4.10,
                       telegram-api >= 0.7,
                       http-client <= 0.5.14,
                       http-client-tls <= 0.3.5.3
1 Like