Strict getContents

Vanessa McHale vamchale at gmail.com
Wed Sep 11 18:36:04 UTC 2019


I believe such a function exists in the strict package.

I agree that it would be good to add such functions to base.

> On Sep 11, 2019, at 1: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


More information about the Libraries mailing list