[Haskell-cafe] Exercise in point free-style

Udo Stenzel u.stenzel at web.de
Fri Sep 1 14:14:44 EDT 2006


Julien Oster wrote:
> While we're at it: The best thing I could come up for
> 
> func2 f g l = filter f (map g l)
> 
> is
> 
> func2p f g = (filter f) . (map g)
> 
> Which isn't exactly point-_free_. Is it possible to reduce that further?

Sure it is:

func2 f g l = filter f (map g l)
func2 f g = (filter f) . (map g)	-- definition of (.)
func2 f g = ((.) (filter f)) (map g)	-- desugaring
func2 f = ((.) (filter f)) . map   	-- definition of (.)
func2 f = flip (.) map ((.) (filter f)) -- desugaring, def. of flip
func2 = flip (.) map . (.) . filter 	-- def. of (.), twice
func2 = (. map) . (.) . filter		-- add back some sugar


The general process is called "lambda elimination" and can be done
mechanically.  Ask Goole for "Unlambda", the not-quite-serious
programming language; since it's missing the lambda, its manual explains
lambda elimination in some detail.  I think, all that's needed is flip,
(.) and liftM2.


Udo.
-- 
I'm not prejudiced, I hate everyone equally.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20060901/0ae6f702/attachment.bin


More information about the Haskell-Cafe mailing list