[Haskell-cafe] Re: Point-free style (Was: Things to avoid)

David Menendez zednenem at psualum.com
Thu Feb 10 23:00:17 EST 2005

Sebastian Sylvan writes:

> Points free style is cool in a geeky sort of way, but not really all
> that useful when you're trying to write clear code that people can
> actually understand.

That's true of badly-written point-free code, certainly. However, anyone
who has spent time doing shell scripting in UNIX should be fairly
comfortable with function composition in principle.

Here's some code I wrote when I was playing around with an RDF
combinator library:

    tsArcFwd s p = maybe [] id . Map.lookup (s,p) . store_sp
    tsArcBwd p o = maybe [] id . Map.lookup (p,o) . store_po

I suppose a point-wise version of these would look like this:

    tsArcFwd s p ts = maybe [] id (Map.lookup (s,p) (store_sp ts))

or this:

    tsArcFwd s p ts =
        case Map.lookup (s,p) (store_sp ts) of
            Just xs -> xs
            Nothing -> []

Here's another one:

    addTriple (s,p,o) = addArc s p o . addNode s . addNode p . addNode o

I like to think it's pretty straightforward.

I suppose you could argue that these are examples of "semi-point-free"
style, or something. Certainly, I wouldn't want to rewrite tsArcFwd or
addTriple into fully point-free style.
David Menendez <zednenem at psualum.com> | "In this house, we obey the laws
<http://www.eyrie.org/~zednenem>      |        of thermodynamics!"

More information about the Haskell-Cafe mailing list