[Haskell-cafe] proper way to generate a random data in criterion
Henk-Jan van Tuyl
hjgtuyl at chello.nl
Wed Oct 19 23:53:01 CEST 2011
On Wed, 19 Oct 2011 21:21:48 +0200, Gregory Collins
<greg at gregorycollins.net> wrote:
> On Wed, Oct 19, 2011 at 5:03 PM, Johan Tibell <johan.tibell at gmail.com>
> wrote:
>>
>> It does. You need to use evaluate to have ensure actually be evaluated.
>>
>
> I'm almost certain you're wrong about this. The bang pattern on the
> return from ensure (!r1 <- ensure $ ...) forces r1 to WHNF, which goes
> through deepseq, and thus the whole list is forced. See
> https://gist.github.com/1299380 for a short counterexample.
>
> G
You don't need the ensure function or the bang patterns if you do it like
this:
main =
deepseq testList $
do
putStrLn "we survived without evaluating testList"
let x = foldl' (+) 0 $ take 50 testList
putStrLn $ "x was " ++ show x
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
More information about the Haskell-Cafe
mailing list