前段时间我写了一些代码,用于从十六进制编码的字符串文字OverloadedStrings
创建ByteString
s,它使用base16-bytestring
. 这工作得很好,但似乎我并没有像我想象的那样理解它。
让我完全困惑的是这个。为什么
{-# LANGUAGE OverloadedStrings #-}
import Data.ByteString.Base16 ()
import qualified Data.ByteString as B
plaintext = "The message" :: B.ByteString
main = print plaintext
编译并运行正常,但如果我删除导入,Data.ByteString.Base16
则编译失败(类似于这个问题):
test.hs:6:13:
No instance for (Data.String.IsString B.ByteString)
arising from the literal `"The message"'
根据Haskell Wiki,像这样的导入“仅用于导入类型类的实例而没有其他用途”,但据我所知,base16-bytestring 源代码没有定义任何类型类实例,只有encode
anddecode
函数.
导入如何IsString
为代码编译提供必要的实例?