<div dir="ltr">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 <a href="http://Data.Text.IO">Data.Text.IO</a> 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.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 11, 2019 at 3:57 PM Joseph C. Sible <<a href="mailto:josephcsible@gmail.com">josephcsible@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">+1 to adding those non-lazy versions. Such functions could work<br>
without having to half-close the handle, thus making it easier to<br>
continue reading from a file after EOF (à la `tail -f`). (I've asked<br>
about how to do this exact thing before at<br>
<a href="https://stackoverflow.com/q/56221606/7509065" rel="noreferrer" target="_blank">https://stackoverflow.com/q/56221606/7509065</a> and this would give it a<br>
trivial answer.)<br>
<br>
Joseph C. Sible<br>
<br>
On Wed, Sep 11, 2019 at 2:01 PM Li-yao Xia <<a href="mailto:lysxia@gmail.com" target="_blank">lysxia@gmail.com</a>> wrote:<br>
><br>
> Hello Libraries,<br>
><br>
> In base, the functions which read all contents from a handle or file<br>
> into one String currently all do lazy IO: readFile, getContents,<br>
> hGetContents.<br>
><br>
> <a href="https://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html#v:hGetContents" rel="noreferrer" target="_blank">https://hackage.haskell.org/package/base-4.12.0.0/docs/System-IO.html#v:hGetContents</a><br>
><br>
> The easiest way to get a strict alternative seems to be to explicitly<br>
> force the list, for example using ```length contents `seq` pure ()```,<br>
> but that's far from an obvious solution.<br>
><br>
> Is there a better way?<br>
><br>
> If not, I propose to add readFile', getContents', hGetContents', which<br>
> don't do lazy IO.<br>
><br>
> It regularly creates confusion among beginners, and it's easy to assume<br>
> that lazy IO is benign if that's the only way to do certain operations,<br>
> when it's arguably the wrong way to read files to begin with.<br>
><br>
> Cheers,<br>
> Li-yao<br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Eric Mertens</div>