[Haskell-cafe] Point-free style

Thomas Jäger thjaeger at gmail.com
Mon Feb 14 09:30:57 EST 2005


Hi,

On Mon, 14 Feb 2005 14:40:56 +0100, Daniel Fischer wrote:
> > > \f g h x y -> f (g x) (h y)
> > ((flip . ((.) .)) .) . (.)
> 
> Cool!
> 
> But I must say, I find the pointed version easier to read (and define).
It certainly is. In fact, I transformed it automatically using a toy
lambdabot plugin, i've recently been writing.

> So back to the question before this one, is there a definite advantage of
> point-free style?
> 
> I tend to use semi-point-free style, but I might be argued away from that.
Yes, me too. I think obscure point-free style should only be used if a
type signature makes it obvious what is going on. Occasionally, the
obscure style is useful, though, if it is clear there is exactly one
function with a specific type, but tiresome to work out the details
using lambda expressions. For example to define a map function for the
continuation monad
> cmap :: (a -> b) -> Cont r a -> Cont r b
One knows that it must look like
> cmap f = Cont . foo . runCont
where foo is some twisted composition with f, so successively trying
the usual suspects ((f.).), ((.f).), ... will finally lead to the only
type-checking and thus correct version (.(.f)), even though I can't
tell what exactly that does without looking at the type or
eta-expanding it.

Thomas


More information about the Haskell-Cafe mailing list