As Nikita Volkov mentioned in his question Data.Text vs String I also wondered why I have to deal with the different String implementations type String = [Char]
and Data.Text
in haskell. In my code I use the pack
and unpack
functions really often.
My question: Is there a way to have an automatic conversion between both string types so that I can avoid writing pack
and unpack
so often?
In other programming languages like Python or JavaScript there is for example an automatic conversion between integers and floats if it is needed. Can I reach something like this also in haskell? I know, that the mentioned languages are weakly typed, but I heard that C++ has a similar feature.
Note: I already know the language extension {-# LANGUAGE OverloadedStrings #-}
. But as I understand this language extensions just applies to strings defined as "..."
. I want to have an automatic conversion for strings which I got from other functions or I have as arguments in function definitions.
Extended question: Haskell. Text or Bytestring covers also the difference between Data.Text
and Data.ByteString
. Is there a way to have an automatic conversion between the three strings String
, Data.Text
and Data.ByteString
?
AsString a => a
just like number literals have typeNum a => a
, but you don't get automatic conversions on runtime values.