On Nov 17, 2007 8:54 PM, Arie Groeneveld <[EMAIL PROTECTED]> wrote: > Haskell has several forms of fold's. foldr1 is comparable with > J's insert. foldr1 doesn't take a starting value > The other fold's in Haskell are: > foldl / foldr <function> <starting value> list
And the difference is not only in <starting value>, but also in the functions' types: foldr1 :: (a -> a -> a) -> [a] -> a foldr :: (a -> b -> b) -> b -> [a] -> b (I mean the function (a -> b -> b)) As an example, for the time being I am convinced, that the following Haskell implementation of "one pass" maximum consecutive sum algorithm via foldr: foldr (\x (csum,csummin,cresult) -> let nsum=x+csum ; nmin=min csummin nsum ; in (nsum,nmin,max cresult (nsum-nmin)) ) (0,0,0) [0, 4, 1, -2, 1, -5, 4, -3, 5, -2, -1, 2, 6, -2, 1, -1] (8,-2,11) cannot be implemented in J using only Insert without, as an option, preliminary boxing as in my implementation of "more generic" foldr above. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
