这是我第一次使用ByteStrings,也是我第一次看到pcap。我基本上试着用ByteStrings高效地读取pcap并在屏幕上打印它的内容。我正在使用Network.Pcap库来读取文件。ByteString变体可以在这里找到:Network.Pcap ByteString。为了简单起见,我只想打印文件的第一行,所以我的代码如下所示:
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函数必须具有type:PktHdr -> ByteString -> IO (),而在2行中,类型是PktHdr -> ByteString -> IO ()。但是,我不能简单地使用ByteString类型,因为这样我就会与普通列表序言中定义的函数发生冲突。你有什么想法吗?
发布于 2015-02-06 14:15:22
编译器试图告诉您您正在使用两个不同的bytestring包。有关详细信息和解决方案,请参见此处:使用Codec.BMP时“无法将预期类型与实际类型匹配”错误
https://stackoverflow.com/questions/28367558
复制相似问题