Haskell ByteString 类型错误

Haskell ByteString type error

这是我第一次使用 ByteStrings,也是我第一次看到 pcap 文件。 我基本上是在尝试 高效地 使用 ByteStrings 读取 pcap 文件并在屏幕上打印其内容。 我正在使用 Network.Pcap library to read the file. The ByteString variant can be found here: Network.Pcap ByteString。为了让事情变得简单,我只想打印文件的 first 行,所以我的代码如下所示:

1 import qualified Data.ByteString as B

2 printIt :: PktHdr -> B.ByteString -> IO ()
3 printIt ph bytep = do
4    print $ hdrCaptureLength ph  -- not important
5    print $ bytep

6 main = do
7    f <- openOffline "file.pcap"
8    dispatchBS f (1) printIt

其中 printIt 是对文件主体进行操作的 callbackBS 函数。

编译器抱怨此消息:

Couldn't match type ‘B.ByteString’
              with ‘bytestring-0.10.4.0:Data.ByteString.Internal.ByteString’
NB: ‘B.ByteString’
      is defined in ‘Data.ByteString.Internal’
          in package ‘bytestring-0.10.4.1’
    ‘bytestring-0.10.4.0:Data.ByteString.Internal.ByteString’
      is defined in ‘Data.ByteString.Internal’
          in package ‘bytestring-0.10.4.0’
Expected type: CallbackBS
  Actual type: PktHdr -> B.ByteString -> IO ()
In the third argument of ‘dispatchBS’, namely ‘printIt’
In a stmt of a 'do' block: dispatchBS f (1) printIt

据我了解,对于编译器,callbackBS 函数的类型必须为:PktHdr -> ByteString -> IO (),而在第 2 行,类型为 PktHdr ->B.ByteString -> IO (). 但是我不能简单地使用 ByteString 类型,因为那样我会与普通列表的前奏中定义的函数发生冲突。 你有什么想法吗?

编译器试图告诉您您正在使用两个不同的 bytestring 包。有关详细信息和解决方案,请参见此处:"Couldn't match expected type with actual type" error when using Codec.BMP