Reputation: 619
It is the first time I use ByteStrings and the first time I ever see a pcap file. I am basically trying to efficiently read the pcap file with ByteStrings and print its content on screen. I am using the Network.Pcap library to read the file. The ByteString variant can be found here: Network.Pcap ByteString. To make things easy I want just to print the first line of the file so my code looks like this:
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
where printIt
is the callbackBS function that operates on the body of the file.
The compiler complains with this message:
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
What I understand is that for the compiler, the callbackBS function must have type: PktHdr -> ByteString -> IO ()
, while at line 2 the types is PktHdr ->
B.ByteString -> IO ()
.
However I can not simply use the type ByteString because then I would incur in conflicts with functions defined in the prelude for normal lists.
Do you have any idea?
Upvotes: 0
Views: 413
Reputation: 13876
Compiler is trying to tell you that you are using two different bytestring
packages. For the details and a solution see here: "Couldn't match expected type with actual type" error when using Codec.BMP
Upvotes: 2