Hello algorithms,

Sunday, August 6, 2006, 1:50:42 PM, you wrote:

> listFoldr f y Nil = y
> listFoldr f y (Cons x xs) = f x (foldr f z xs)

this is definitely wrong - using foldr instead of listFoldr and 'z'
appearing from nowhere :)


> listFoldr f y Nil = y
> listFoldr f y (Cons x xs) = f y (listFoldr f (f y x) xs)

y is a final value that should be used only at the last point. for
example:

sum = foldr1 (+) 0

sum [1,2,3] = 1+2+3+0

so, 'y' in second statement for listFoldr should be passed to
recursive call of listFoldr (so it can be eventually used by the first
statemnet) but not used in call to f. second, your definition calls
'f' two times, so the final result will be something like:

sum [1,2,3] = 1+2+3+(1+2+3+0)

(you can try)


-- 
Best regards,
 Bulat                            mailto:[EMAIL PROTECTED]

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to