[Haskell-beginners] Opaque (to me) compilation error
Theodore Lief Gannon
tanuki at gmail.com
Sat Nov 14 02:24:24 UTC 2015
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.
On Fri, Nov 13, 2015 at 8:41 PM, Dan Stromberg <strombrg at gmail.com> wrote:
>
> In the following code:
> prefix_md5 :: String -> Data.ByteString.ByteString
> prefix_md5 filename = do
> let prefix_length = 1024
> file <- System.IO.openBinaryFile filename System.IO.ReadMode :: (IO
> System.IO.Handle)
> data_read <- Data.ByteString.hGet file prefix_length :: (IO
> Data.ByteString.ByteString)
> _ <- System.IO.hClose file
> let hasher = Crypto.Hash.MD5.init :: Crypto.Hash.MD5.Ctx
> let hasher2 = Crypto.Hash.MD5.update hasher data_read ::
> Crypto.Hash.MD5.Ctx
> let digest = Crypto.Hash.MD5.finalize hasher2 ::
> Data.ByteString.ByteString
> return digest :: (IO Data.ByteString.ByteString)
>
> I get the error:
> Md5s.hs:13:5:
> Couldn't match type `IO Data.ByteString.ByteString'
> with `Data.ByteString.ByteString'
> Expected type: IO System.IO.Handle
> -> (System.IO.Handle -> IO Data.ByteString.ByteString)
> -> Data.ByteString.ByteString
> Actual type: IO System.IO.Handle
> -> (System.IO.Handle -> IO Data.ByteString.ByteString)
> -> IO Data.ByteString.ByteString
> In a stmt of a 'do' block:
> file <- System.IO.openBinaryFile filename System.IO.ReadMode ::
> IO System.IO.Handle
>
> 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!
>
> How might I correct this function to eliminate the error?
>
> Thanks!
>
> --
> Dan Stromberg
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151113/dcac0cc7/attachment.html>
More information about the Beginners
mailing list