
28 Mar
2009
28 Mar
'09
2:01 a.m.
Brandon S. Allbery KF8NH
On 2009 Mar 28, at 0:59, Jeff Lasslett wrote:
myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]] myGroupBy p xs = foldr step [[]] xs where -- step :: a -> [ [ a ] ] -> [ [ a ] ] step x acc@( ys : yss ) | null ys = [ x ] : []
I wonder whether that line does anything? foldr is defined like this: foldr step zero (x:xs) = step x (foldr step zero xs) So it seems to me that when the step function doesn't affect either the accumulator(=zero) or xs, then the step function won't have any effect on the result foldr produces. The return value from your 'null ys' guard does not affect xs, nor does it change the accumulator acc. So how does it affect the result of foldr?