[Haskell-beginners] Ignoring the result of a monadic computation

Brent Yorgey byorgey at seas.upenn.edu
Fri Nov 19 15:02:57 EST 2010


On Fri, Nov 19, 2010 at 08:39:44PM +0100, Tim Baumgartner wrote:
> Hi Haskellers,
> 
> this was my first post and I'm thankful and really impressed how
> many qualified answers I got. I've been learning Haskell only for a
> short time but I'm really fascinated how mathematical and expressive
> a programming language can be (I usually code Java). Recently I read
> a blog post, with a function
> 
> map (length &&& head) . group
> 
> that was much shorter and more elegant than the corresponding Python
> code. That was the main reason for me to try to write my own code in
> a single line without any lambda expressions.

Indeed!  Writing code without lambda expressions or mentioning
parameters is called "point-free style" (since parameters are
sometimes referred to in the mathematical literature as "points").
For example,

  foo y = bar (baz (frob y))

can be rewritten as

  foo = bar . baz . frob

which is (in most people's opinion) much nicer.  Lambdabot (in the
#haskell IRC channel on freenode.org) has a @pl command for performing
such point-free simplifications.  Point-free style should be taken in
moderation, since it can be taken to unreadably esoteric extremes, but
you are not in danger yet of crossing that line. =)

-Brent


More information about the Beginners mailing list