Strict getContents
Eric Mertens
emertens at gmail.com
Thu Sep 12 02:41:49 UTC 2019
I like the idea of having strict versions of these functions. I also prefer
to recommend people use the strict versions of these functions from text
package's Data.Text.IO to encouraging using String to load files. I agree
that people should be able to read file contents strictly without having to
use tricks like forcing the length.
On Wed, Sep 11, 2019 at 3:57 PM Joseph C. Sible <josephcsible at gmail.com>
wrote:
> +1 to adding those non-lazy versions. Such functions could work
> without having to half-close the handle, thus making it easier to
> continue reading from a file after EOF (à la `tail -f`). (I've asked
> about how to do this exact thing before at
> https://stackoverflow.com/q/56221606/7509065 and this would give it a
> trivial answer.)
>
> Joseph C. Sible
>
> On Wed, Sep 11, 2019 at 2:01 PM Li-yao Xia <lysxia at gmail.com> wrote:
> >
> > Hello Libraries,
> >
> > In base, the functions which read all contents from a handle or file
> > into one String currently all do lazy IO: readFile, getContents,
> > hGetContents.
> >
> >
> https://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html#v:hGetContents
> >
> > The easiest way to get a strict alternative seems to be to explicitly
> > force the list, for example using ```length contents `seq` pure ()```,
> > but that's far from an obvious solution.
> >
> > Is there a better way?
> >
> > If not, I propose to add readFile', getContents', hGetContents', which
> > don't do lazy IO.
> >
> > It regularly creates confusion among beginners, and it's easy to assume
> > that lazy IO is benign if that's the only way to do certain operations,
> > when it's arguably the wrong way to read files to begin with.
> >
> > Cheers,
> > Li-yao
> > _______________________________________________
> > Libraries mailing list
> > Libraries at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
--
Eric Mertens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190911/6e6f22ef/attachment-0001.html>
More information about the Libraries
mailing list