[Haskell-cafe] timing question
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
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:
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?
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe