3 ms·
That's filter, not reduce. :)
by mbrubeck 17y ago
That's filter, not reduce. :)
- jganetsk 17y agoHe's right with the second one. r' f (x:xs) | xs == [] = x | otherwise = f x (r' f xs) r' :: (Eq t) => (t -> t -> t) -> [t] -> t That's definitely not filter. That's definitely reduce. (I'm equating reduce with foldr1 or foldl1). Now, because he used the == operator, that adds the (Eq t) constraint. We can rewrite his code as the following... r' f (x:xs) = case xs of {[] -> x; _ -> f x (r' f xs)} r' :: (t -> t -> t) -> [t] -> t Try actually running it on some code. r' (+) [1,2,3,4] evaluates to 10
- mbrubeck 17y agoThe "filter" version was deleted and the correct version added, after I wrote my comment.