[Haskell-cafe] Point-free style
Daniel Fischer
daniel.is.fischer at web.de
Tue Feb 15 05:42:46 EST 2005
Am Dienstag, 15. Februar 2005 00:42 schrieben Sie:
> On Feb 14, 2005, at 2:07 AM, Daniel Fischer wrote:
> > A question for the point-free society:
> > Is there any advantage of defining
> >
> > (.<) = (.) . (.)
> >
> > rather than
> >
> > f .< g = \x y -> f (g x y) -- or f $ g x y ?
> >
> > Analogous question for (.) . (.) . (.) etc.
>
> Well, from the fact that you even pose the question, and
> notwithstanding wise
> remarks from Simon Marlow, I'm guessing that "out of sheer impish
> delight" or
> "to tickle the aesthetic sense the way a bump to the elbow tickles the
> funny bone"
> are not the sort of answers you're looking for :) .
No, although I appreciate them and often do things (among them point-freeing
my code -- I've not reached mastery in that department yet) for exactly these
reasons, what I was looking for, were reasons such as
- Oh, indeed this gives better performance,
- Well, it makes no difference in performance, but it's easier to handle for
the compiler,
or whatever else there might be.
L'art pour l'art is great, but as Simon Marlow pointed out, it's valuable to
write code so that you (and other people) can understand it when you read it
some time later. And there I think that point-freeing has a tendency to
require more extensive comments.
>
> (Note that others have since risen to the occasion in this vein. And
> remember that all
> these "dotted dots" were Jerzy's fault, not mine, and that beer was at
> hand ... .)
Why "fault"?, I find all this quite interesting.
>
> More seriously, however, the generalization to n raises some
> interesting issues.
> For surely we are tempted to something like this, in a half-imagined
> syntax
> (read the LHS as "dot sub n"):
>
> (. _ n) = foldl1 (.) (replicate n (.))
>
> And, just as surely, we shouldn't be satisfied with the answer
> "Hindley-Milner
> don't do dat" * . Rather, we should seek out ways to extend the type
> system and
> the language so that we could make this abstraction, and others like
> it, which
> are compelling at some basic level.
>
> The point being, this generalization might not occur to us (and drive
> us to
> new heights, etc.) if we didn't express it in the more "precious" style.
>
> -- Fritz
This is the sort of reason for point-free style that I was looking for.
>
> PS: Which is not to say that the Haskell type system can't be wrenched
> (coerced,
> cajoled, gently plied with sweet whispers ...) into doing things
> *similar* to
> this, using type-level natural numbers, or perhaps
> existentially-quantified data
> constructors. I'm sure that "extreme typists" like Oleg and Ken do this
> sort of
> thing to warm up in the morning, the way other typists (the mundane
> sort) lace
> their fingers together and stretch them out before settling in to their
> 60-words-per-minute day.
>
> But perhaps someone else should post some code along these lines, lest
> Oleg and
> Ken despair too much of having wasted their efforts on us. I promise to
> try out
> a few ideas myself when I get the chance.
>
>
> * (take no offense: just a reference to the old "In Living Color"
> variety show)
I don't know that, so the pun's wasted on me, pity.
Daniel
More information about the Haskell-Cafe
mailing list