News for hackers. Stuff that matters.
Re:Guido on Functional by jdeseno on Monday March 08, 2010 @05:20PM (#1176664)
Couldn't we do this?

r' f (x:xs) | xs == [] = (f x):[] | otherwise = (f x):(r' f xs)

or:

[(f a) | a <- myList]

- another edit -

r' f (x:xs) | xs == [] = x | otherwise = f x (r' f xs)

Re:Guido on Functional by mbrubeck on Monday March 08, 2010 @05:24PM (#1176674)
That's map, not reduce.
[deleted]
Re:Guido on Functional by mbrubeck on Monday March 08, 2010 @05:35PM (#1176702)
That's filter, not reduce. :)
Re:Guido on Functional by jganetsk on Monday March 08, 2010 @07:56PM (#1177083)
He'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

Re:Guido on Functional by mbrubeck on Monday March 08, 2010 @09:29PM (#1177298)
The "filter" version was deleted and the correct version added, after I wrote my comment.