I wrote some code a while ago which uses OverloadedStrings
to create ByteString
s from hex-encoded String literals, which it decodes using the functions provided by base16-bytestring
. This worked fine, but it seems I didn't understand it as well as I thought.
The thing that has me completely confused is this. Why does
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Base16 ()
import qualified Data.ByteString as B
plaintext = "The message" :: B.ByteString
main = print plaintext
compile and run OK, but if I remove the import for Data.ByteString.Base16
then it fails to compile (similar to this question):
test.hs:6:13:
No instance for (Data.String.IsString B.ByteString)
arising from the literal `"The message"'
According to the Haskell Wiki, an import like this is "useful for only importing instances of typeclasses and nothing else", but as far as I can see, the base16-bytestring source code doesn't define any typeclass instances, just the encode
and decode
functions.
How does the import provide the necessary instance of IsString
for the code to compile?