[Haskell-cafe] Re: [Haskell] Trying to get a Composite design pattern to work

Chris Kuklewicz haskell at list.mightyreason.com
Tue Mar 14 20:06:45 EST 2006


Chris Kuklewicz wrote:
> Neil Mitchell wrote:
>>> How's this?
>> What about ++, in Haskell thats just an ordinary function, yet you are
>> using the library one in this case.
> 
> (++) a b = foldr (:) b a
> 
> or
> 
> (++) = flip (foldr (:))
> 
> so
> 
> concat = foldr (flip (foldr (:))) []
> 
> also
> 
> map = (\f -> foldr ((:).f) [])
> 
> thus
> 
> concatMap = (\f -> (foldr (flip (foldr (:))) []) . (foldr ((:).f) []))
> 
> No recursive definitions in sight...all built with foldr
> 

Of course, I should only need one [] in the optimal definition:

concatMap = (\f -> (foldr (flip (foldr (:)).f) []))

Which lambdabot can make "pointless" by eliminating the \f->

concatMap = flip foldr [] . (flip (foldr (:)) .)

-- 
Chris


More information about the Haskell-Cafe mailing list