
Hi, We can define filter using foldr as under: filter1 p = foldr (\x xs -> (if (p x) then (x:xs) else xs)) [] Can we define filter using foldr but in pointfree style? Thanks -DM

On Tue, Nov 10, 2009 at 12:47 PM, damodar kulkarni
Hi, We can define filter using foldr as under:
filter1 p = foldr (\x xs -> (if (p x) then (x:xs) else xs)) []
Can we define filter using foldr but in pointfree style?
Pointfree code is (nearly) always possible, but sometimes not very desirable. The first thing to do is to ask lambdabot for help; in this case, the answer is.. this: filter1 = flip foldr [] . flip flip id . (ap .) . (`ap` (:)) . (((.) . if') .) if' p a b = if p then a else b Now, there may be a better way to go about this, but I don't think I'd bother trying. The pointful variant seems quite readable as-is. :P -- Svein Ove Aas
participants (2)
-
damodar kulkarni
-
Svein Ove Aas