[Haskell-cafe] timing question

Luke Palmer lrpalmer at gmail.com
Sun Aug 3 13:24:23 EDT 2008


On Sun, Aug 3, 2008 at 11:06 AM, Arie Groeneveld <bradypus at xs4all.nl> wrote:

> Sorry, should go the forum.
>
> Ok, thanks. In this case the list consists of 6-digit alphanumeric
> codes. So doing something like:
>
> foldl1 (\x y -> g y) xs


No, that still doesn't force elements.  Let's say g is (+1):

f = \x y -> (+1) y
foldl1 f [1,2,3]

(1 `f` 2) `f` 3
(+1) 3
4

So we don't need to compute (+1) on any numbers but 3.

The most direct way is to force the elements of the list:

import Control.Parallel.Strategies
seqList rwhnf (map g xs)

Note that the notion of "compute" in this example is to WHNF, so for example
if g produces lists, it will only evaluate far enough to determine whether
the list is a nil or a cons, not the whole thing.


> will do the job?
>
>
> =@@i
>
>
> Bulat Ziganshin schreef:
>
>> Hello Arie,
>>
>> Sunday, August 3, 2008, 1:56:43 PM, you wrote:
>>
>> *Main>> last . f $ xs
>>
>> this way you will get only "spin" of list computed, not elements
>> itself. something like sum should be used instead
>>
>>
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080803/ee06fe99/attachment.htm


More information about the Haskell-Cafe mailing list