【发布时间】:2013-02-02 21:21:49
【问题描述】:
我不久前写了一些代码,它使用OverloadedStrings 从十六进制编码的字符串文字创建ByteStrings,它使用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 的导入,则编译失败(类似于this question):
test.hs:6:13:
No instance for (Data.String.IsString B.ByteString)
arising from the literal `"The message"'
根据Haskell Wiki,像这样的导入“仅对导入类型类的实例有用”,但据我所知,base16-bytestring 源代码没有定义任何类型类实例,只有encode 和decode 函数。
导入如何为代码编译提供IsString 的必要实例?
【问题讨论】:
标签: haskell