Couldn't match expected type `Text' with actual type `[Char]'

Unfortunately, Haskell has several conflicting types for strings of characters. String literals are usually of type String which is just an alias for [Char]. Because that is an inefficient representation of strings, there are alternatives, like Text.

In your case, adding {-# LANGUAGE OverloadedStrings #-} as the first line of your program will make it compile. Basically your string literals can be of type Text then.

In the case of ghci you can run :set -XOverloadedStrings.


In my case I had code that was doing concatenation of a String and Text value:

"cd " ++ stackProjectLocation

"cd " was being of type Text because of using {-# LANGUAGE OverloadedStrings #-}

And stackProjectLocation was a String

The solution was to use (<>) :: Semigroup a => a -> a -> a:

"cd " <> stackProjectLocation

Tags:

Haskell