I'm passing a (strict) ByteString to something expecting a System.IO.FilePath, which is declared as type FilePath = String. I'm also using {-# LANGUAGE OverloadedStrings #-}. I've had conversions in some places happen automatically, but here it does not. What have I got wrong?
Main.hs:33:40: error:
• Couldn't match type ‘ByteString’ with ‘[Char]’
Expected type: FilePath
Actual type: ByteString
The
{-# LANGUAGE OverloadedStrings #-}pragma only works for string literals, like"a string". In that case, Haskell implicitly places afromStringbefore every string literal, so it rewrites a string literal as"a string"tofromString "a string". This only happens for literals.In Haskell, as far as I know, there are no implicit conversions. Conversions between for instance
IntandFloatare all explicit.Furthermore note that the
IsStringtypeclass only has a functionfromString :: String -> a. So that means it works only from a string to that instance (hereByteString), not the other way around.You can use the
unpack :: ByteString -> Stringto convert theByteStringto aString.