I'm a beginner at Haskell.
I have a question.
parseDnsMessage::BG.BitGet DnsMessage
recQuery::BS.ByteString->String->IOBS.ByteString
resolveName::[Word8]->[Word8]->BS.ByteString->String
resolveName qname name bstr=do
let newbstr = BSL.toStrict$replace(BS.pack qname) (BS.pack name) bstr
retbstr<-recQuery newbstr (head rootServers 4)
let msg = BG.runBitGet retbstr parseDnsMessage
case msg of
Right m->(intercalate .. $$map show(rdata$head$answer$m))
--- The following error message ---
Couldn't match expected type '[BSI.ByteString]'
with actual type 'IO BSI.ByteString'
Inastmt of a'do' block:
retbstr<-recQuery newbstr (head rootServers 4)
In the expression:
do {let newbstr
= BSL.toStrict$replace(BS.pack qname)(BS.pack name)bstr;
retbstr<-recQuery newbstr(head rootServers4);
let msg = BG.runBitGet retbstr parseDnsMessage;
case msg of {
Right m
->(intercalate"."$map show(rdata$head$answer$m))}
How is it appropriate to write in such a case?
Thank you for your cooperation.
Although the do notation appears to be processed by <-
while extracting the contents, there are restrictions, and the value represented by the entire do notation must be the type of monad from which the contents are taken out.
In other words, if you want to use <-
to describe something, the result must also be IO.
So at least resolveName is
resolveName::[Word8]->[Word8]->BS.ByteString->IO String
It should be.In order to achieve this, I think the functions required will be those that achieve String->IO String
.You can use return
for this.
If you feed the return value of the last intercalate
and transform it into a correct shape, you will get what you want.
© 2024 OneMinuteCode. All rights reserved.