【发布时间】:2015-02-06 14:06:49
【问题描述】:
这是我第一次使用 ByteStrings,也是我第一次看到 pcap 文件。 我基本上是在尝试有效地使用 ByteStrings 读取 pcap 文件并在屏幕上打印其内容。 我正在使用Network.Pcap library 来读取文件。 ByteString 变体可以在这里找到: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.@ 987654329@。
但是我不能简单地使用 ByteString 类型,因为那样我会与正常列表的前奏中定义的函数发生冲突。
你有什么想法吗?
【问题讨论】:
标签: haskell pcap bytestring