<div dir="ltr">You're missing IO in the type declaration, which I believe means that do block is running in the Id monad -- by inference, Id ByteString.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 13, 2015 at 8:41 PM, Dan Stromberg <span dir="ltr"><<a href="mailto:strombrg@gmail.com" target="_blank">strombrg@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><br>In the following code:<br><div style="margin-left:40px">prefix_md5 :: String -> Data.ByteString.ByteString<br>prefix_md5 filename = do<br> let prefix_length = 1024<br> file <- System.IO.openBinaryFile filename System.IO.ReadMode :: (IO System.IO.Handle)<br> data_read <- Data.ByteString.hGet file prefix_length :: (IO Data.ByteString.ByteString)<br> _ <- System.IO.hClose file<br> let hasher = Crypto.Hash.MD5.init :: Crypto.Hash.MD5.Ctx<br> let hasher2 = Crypto.Hash.MD5.update hasher data_read :: Crypto.Hash.MD5.Ctx<br> let digest = Crypto.Hash.MD5.finalize hasher2 :: Data.ByteString.ByteString<br> return digest :: (IO Data.ByteString.ByteString)<br></div><br clear="all"></div>I get the error:<br><div style="margin-left:40px">Md5s.hs:13:5:<br> Couldn't match type `IO Data.ByteString.ByteString'<br> with `Data.ByteString.ByteString'<br> Expected type: IO System.IO.Handle<br> -> (System.IO.Handle -> IO Data.ByteString.ByteString)<br> -> Data.ByteString.ByteString<br> Actual type: IO System.IO.Handle<br> -> (System.IO.Handle -> IO Data.ByteString.ByteString)<br> -> IO Data.ByteString.ByteString<br> In a stmt of a 'do' block:<br> file <- System.IO.openBinaryFile filename System.IO.ReadMode ::<br> IO System.IO.Handle<br></div><br></div>How should I interpret that error to solve this kind of problem on my own in the future? I don't see where the line in question does anything with ByteString's!<br><br></div>How might I correct this function to eliminate the error?<br><br></div>Thanks!<span class="HOEnZb"><font color="#888888"><br><div><div><div><br><div>-- <br><div>Dan Stromberg</div>
</div></div></div></div></font></span></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>