[Haskell-beginners] Opaque (to me) compilation error

Kim-Ee Yeoh ky3 at atamo.com
Sat Nov 14 09:44:24 UTC 2015


On Sat, Nov 14, 2015 at 10:52 AM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:

> What we're seeing is special handling for stage 3: reporting errors in a
> do-block. Sometimes it helps, sometimes it hinders. For instance, the
> derivation of this signature is confusing indeed:
>


>    IO System.IO.Handle
> -> (System.IO.Handle -> IO Data.ByteString.ByteString)
> -> Data.ByteString.ByteString
>

To elaborate, the error message comes from the compiler choking on the
monadic bind (>>=) that reveals itself in the desugared code.

The (>>=) results from desugaring

   file <- openBinaryFile filename ReadMode

into

   openBinaryFile filename ReadMode >>= \file -> ...

The compiler knows the type signature of (>>=), which wants to see

   IO Handle -> (Handle -> IO ByteString) -> IO ByteString

But the signature of the top-level function insists on

   IO Handle -> (Handle -> IO ByteString) -> ByteString

This is what's the compiler's trying to say.


-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151114/f1ead8c1/attachment.html>


More information about the Beginners mailing list