Couldn't match expected type `text-1.2.4.0:Data.Text.Internal.Text' with actual type `[Char]'

I’m trying a simple telegram-api example:

module Main where

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 "bot8333589:AAdsgsgsfgsgsgddsgsgdh"

but I get

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:18:23: error:
* Couldn’t match expected type text-1.2.4.0:Data.Text.Internal.Text' with actual type [Char]’
* In the first argument of Token', namely “bot8333589:AAdsgsgsfgsgsgddsgsgdh”’

I don’t get why this happens since it’s a simple text, it should be understood as [Char]. It’s how its done in the example

You need to add {-# LANGUAGE OverloadedStrings #-} to the top of your module.

2 Likes

it should be understood as [Char].

It is indeed understood as [Char], you are correct about that! :slight_smile: When the error message says “actual type: [Char]”, it is telling you that the expression’s type is [Char]. The problem is that the expected type – that is, the parameter of the Token function – is not [Char]. Token is a function with the type Text -> Token. The Text type is essentially equivalent to [Char], just a different data structure that people like to use instead because its representation in memory is more compact. The example has the OverloadedStrings language extension enabled, which implicitly applies the fromString function to every string literal. In this case, this conversion automatically turns the string into Text.

3 Likes