Proposal: end lazy IO results with errors/exceptions
Roman Cheplyaka
roma at ro-che.info
Tue Jul 22 00:37:53 UTC 2014
Agreed, this sounds like a great idea.
* Joachim Breitner <mail at joachim-breitner.de> [2014-07-21 22:21:43+0200]
> Hi,
>
> superficially¹ +1
>
> Joachim
>
> ¹ I like the idea, but can’t tell what the downsides are.
>
>
> Am Montag, den 21.07.2014, 16:16 -0400 schrieb David Feuer:
> > Currently,
> >
> > withFile "foo" hGetContents >>= putStrLn
> >
> > prints out an empty line, the better to confuse newbies.
> >
> > I propose modifying the lazyRead function in GHC.IO.Handle.Text that
> > currently reads
> >
> > lazyRead :: Handle -> IO String
> > lazyRead handle =
> > unsafeInterleaveIO $
> > withHandle "hGetContents" handle $ \ handle_ -> do
> > case haType handle_ of
> > ClosedHandle -> return (handle_, "")
> > SemiClosedHandle -> lazyReadBuffered handle handle_
> > _ -> ioException
> > (IOError (Just handle) IllegalOperation "hGetContents"
> > "illegal handle type" Nothing Nothing)
> >
> > to something like
> >
> > lazyRead :: Handle -> IO String
> > lazyRead handle =
> > unsafeInterleaveIO $
> > withHandle "hGetContents" handle $ \ handle_ -> do
> > case haType handle_ of
> > ClosedHandle -> return (handle_, error "Forcing the
> > result of a lazy read led to an attempt to read from a closed
> > handle.")
> > SemiClosedHandle -> lazyReadBuffered handle handle_
> > _ -> ioException
> > (IOError (Just handle) IllegalOperation "hGetContents"
> > "illegal handle type" Nothing Nothing)
> >
> > Ideally that error should instead be something to throw an imprecise
> > exception, but I don't know how to use those yet. I can't personally
> > see a way for this to break sane, working code, but the folks on #ghc
> > thought it should be discussed and debated on list.
> >
> > David Feuer
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://www.haskell.org/mailman/listinfo/libraries
> >
>
> --
> Joachim Breitner
> e-Mail: mail at joachim-breitner.de
> Homepage: http://www.joachim-breitner.de
> Jabber-ID: nomeata at joachim-breitner.de
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140722/edd7b436/attachment.sig>
More information about the Libraries
mailing list