Scotty Jamison
Scotty Jamison

Reputation: 13289

How do you write functional code that is not point-free (tacit)?

Edit

Based on comments and close-vote flags, I'm seeing that I didn't clearly articulate what I'm trying to ask. So let me state it as succinctly and as straight-forwards as possible.

What does it mean to write non-tacit functional code?

Any answer that answers that question is valid. Everything below is just additional context explaining why I'm asking the question and trying to show my knowledge gap, but if it's just confusing, ignore it.

Original question

Some background

If I were to define functional programming, I would describe it as the art of decomposing problems into small re-usable functions, and then composing those functions together (with pipelines, a compose operator, partial application, etc) to build your program. If you can compose pieces of your program as a series of pure steps in a pipeline, you're doing functional programming. Things like function purity and first-class functions are related to the paradigm and have become very popular concepts, but I don't see them as the core of the paradigm.

I like this definition because it actually feels like I'm describing a paradigm - a way to approach solving a problem, as opposed to, say, defining functional programming simply as "writing pure functions" - function purity is just a technique, not a whole paradigm. Resources like Wikipedia seem to agree with my general conclusion here, where it describes functional programs as "programs [that] are constructed by applying and composing functions".

If I were to define point-free programming (tacit programming), I would define it in a similar fashion - it's the technique of building functions through partial application or function composition, as opposed to explicitly defining the function by hand, by explicitly naming all of the parameters it takes, etc.

The problem

I'm realizing that my definition for point-free programming largely overlaps with my definition for functional programming - sort of like two sides of the same coin. With functional programming, we're breaking up a problem into pieces and composing those pieces together through the use of point-free programming. However, I know that these two terms aren't meant to be interchangable, and I see plenty of places online that say it's possible to do functional programming without following the point-free style.

Which leads me to my question: How do you write functional code that is not point-free? What would be an example of this (written in whatever multi-paradigm language you'd like - I'm specifically asking for a multi-paradigm language so I can picture what a similar example would look like if it's not written in a functional style at all)? I'm assuming my definitions are off - how are they wrong? What would be a better definition(s)?

Upvotes: -2

Views: 104

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 120239

Functional programming is programming with functions, while point-free programming is programming with combinators. All combinators are functions, but not all functions are combinators.

In order to effectively program with combinators, one needs a fairly rich repertoire of predefined (primitive) combinators to start with. If you go with a minimal set instead... Well, try to program something non-trivial in SKI and see how it goes.

So while an important tool in computation theory and other wonderful branches of mathematics I have no clue about, point-free (a k.a. combinatorial) programming is rarely used in practice in its pure form. If you need a combinator that is not in the predefined set or cannot be easily expressed with previously defined combinators, you just define one as a plain old function and move on.

Upvotes: 0

Related Questions