3 ms·
Haskell has the different semantics though they share the literal type. In Haskell there's Text for Unicode strings (UTF-16 encoded) and ByteString for, well, b
by tel 13y ago
Haskell has the different semantics though they share the literal type. In Haskell there's Text for Unicode strings (UTF-16 encoded) and ByteString for, well, byte-strings (fixed vectors of Word8s). The semantics make it hard to confuse them, though if you turn on the OverloadedStrings extension then
"foo"
is ambiguous. If you don't like that you can just not turn on that extension and then there is no literal syntax for either type and you must convert literal strings (really just lists of characters, [Char]) to either type manually
Data.Text.pack "foo" :: Text
Data.ByteString.pack "foo" :: ByteString
Finally, you must use manual encoding functions to interconvert them
Data.Text.Encoding.encodeUtf8 :: Text -> ByteString
- fulafel 13y agoPython has separate bytes and unicode types as well, I think he meant there should be a "black box" type that the program shouldn't try to interpret.
- tel 13y agoI don't think you can really play the same game in Python. The idea of separation of types that occurs in Haskell will really require static typing. It means that entire processing pipelines in your code are completely specialized to one type of string or the other (or generalized to both) with no uncertainty.