Tacit programming

Short description: Programming paradigm

Programming paradigms

* Action
* Agent-oriented
* Array-oriented
* Automata-based
* Concurrent computing
* Relativistic programming
* Data-driven
* Declarative (contrast: Imperative)
* Functional
* Functional logic
* Purely functional
* Logic
* Abductive logic
* Answer set
* Concurrent logic
* Functional logic
* Inductive logic
* Constraint
* Constraint logic
* Concurrent constraint logic
* Dataflow
* Flow-based
* Reactive
* Ontology
* Differentiable
* Dynamic/scripting
* Event-driven
* Function-level (contrast: Value-level)
* Point-free style
* Concatenative
* Generic
* Imperative (contrast: Declarative)
* Procedural
* Object-oriented
* Polymorphic
* Intentional
* Language-oriented
* Domain-specific
* Literate
* Natural-language programming
* Metaprogramming
* Automatic
* Inductive programming
* Reflective
* Attribute-oriented
* Macro
* Template
* Non-structured (contrast: Structured)
* Array
* Nondeterministic
* Parallel computing
* Process-oriented
* Probabilistic
* Quantum
* Set-theoretic
* Stack-based
* Structured (contrast: Non-structured)
* Block-structured
* Structured concurrency
* Object-oriented
* Actor-based
* Class-based
* Concurrent
* Prototype-based
* By separation of concerns:
* Aspect-oriented
* Role-oriented
* Subject-oriented
* Recursive
* Symbolic
* Value-level (contrast: Function-level)

* v
* t
* e

Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are combinators that manipulate the arguments. Tacit programming is of theoretical interest, because the strict use of composition results in programs that are well adapted for equational reasoning.[1] It is also the natural style of certain programming languages, including APL and its derivatives,[2] and concatenative languages such as Forth. The lack of argument naming gives point-free style a reputation of being unnecessarily obscure, hence the epithet "pointless style".[1]

Unix scripting uses the paradigm with pipes.

The key idea in tacit programming is to assist in operating at the appropriate level of abstraction.

## Contents

* 1 Examples
* 1.1 Python
* 1.2 Functional programming
* 1.3 APL family
* 1.4 Stack-based
* 1.5 Unix pipeline
* 2 See also
* 3 References
* 4 External links

## Examples

### Python

Tacit programming can be illustrated with the following Python code. A sequence of operations such as the following:

def example(x):
return baz(bar(foo(x)))

... is written in point-free style as the composition of a sequence of functions, without parameters:[3]

from functools import partial, reduce
def compose(*fns):
return partial(reduce, lambda v, fn: fn(v), fns)

example = compose(foo, bar, baz)

For a more complex example, the Haskell code `p = ((.) f) . g` can be translated as:

p = partial(compose, partial(compose, f), g)

### Functional programming

A simple example (in Haskell) is a program which computes the sum of a list of numbers. We can define the sum function recursively using a pointed style (cf. value-level programming) as:

sum (x:xs) = x + sum xs
sum [] = 0

However, using a fold we can replace this with:

sum xs = foldr (+) 0 xs

And then the argument is not needed, so this simplifies to

sum = foldr (+) 0

which is point-free.

Another example uses function composition:

p x y z = f (g x y) z

The following Haskell-like pseudo-code exposes how to reduce a function definition to its point-free equivalent:

p = \x -> \y -> \z -> f (g x y) z
= \x -> \y -> f (g x y)
= \x -> \y -> (f . (g x)) y
= \x -> f . (g x)
(* Here the infix compose operator "." is used as a curried function. *)
= \x -> ((.) f) (g x)
= \x -> (((.) f) . g) x

p = ((.) f) . g

Finally, to see a complex example imagine a map filter program which takes a list, applies a function to it, and then filters the elements based on a criterion

mf criteria operator list = filter criteria (map operator list)

It can be expressed point-free[4] as

mf = (. map) . (.) . filter

Note that, as stated previously, the points in 'point-free' refer to the arguments, not to the use of dots; a common misconception.[5]

A few programs have been written to automatically convert a Haskell expression to a point-free form.

### APL family

In J, the same sort of point-free code occurs in a function made to compute the average of a list (array) of numbers:

avg=: +/ % #

`+/` sums the items of the array by mapping (`/`) summation (`+`) to the array. `%` divides the sum by the number of elements (`#`) in the array.

Euler's formula [math]\displaystyle{ e^{ix} = \cos x + i\sin x, }[/math] expressed tacitly:

cos =: 2 o. ]
sin =: 1 o. ]
Euler =: ^@j. = cos j. sin

(`j.` is a primitive function whose monadic definition is `0j1` times x and whose dyadic definition is `x+0j1×y`.) The same tacit computations expressed in Dyalog APL:

avg ← +⌿ ÷ ≢

cos ← 2 ○ ⊢
sin ← 1 ○ ⊢
EulerCalc←   cos + 0j1 × sin   ⍝ 0j1 is what's usually written as i
EulerDirect← *0J1×⊢            ⍝ Same as ¯12○⊢
⍝ Do the 2 methods produce the same result?
EulerCheck← EulerDirect=EulerCalc
EulerCheck ¯1 1 2 3
1 1 1 1
⍝ Yes, so far so good!

### Stack-based

In stack-oriented programming languages (and concatenative ones, most of which are stack based), point-free methods are commonly used. For example, a procedure to compute the Fibonacci numbers might look like the following in PostScript:

/fib

dup dup 1 eq exch 0 eq or not

dup 1 sub fib
exch 2 sub fib
add
} if
} def

### Unix pipeline

Main page: Pipeline (Unix)

In Unix scripting the functions are computer programs which receive data from standard input and send the results to standard output. For example,

sort | uniq -c | sort -rn

is a tacit or point-free composition which returns the counts of its arguments and the arguments, in the order of decreasing counts. The 'sort' and 'uniq' are the functions, the '-c' and '-rn' control the functions, but the arguments are not mentioned. The pipe '|' is the composition operator.

Due to the way pipelines work, it is only normally possible to pass one "argument" at a time in the form of a pair of standard input/output stream. Although extra file descriptors can be opened from named pipes, this no longer constitutes a point-free style.

## See also

* Combinatory logic
* Concatenative programming language
* Function-level programming
* Joy (programming language), modern highly tacit language

## References

1. ↑ 1.0 1.1 Manuel Alcino Pereira da Cunha (2005) Point-free Program Calculation
2. ↑ W. Neville Holmes, ed. (2006) Computers and People
3. ↑ "Name code not values". Concatenative.org. http://concatenative.org/wiki/view/Concatenative language/Name code not values. Retrieved 13 September 2013.
4. ↑ pipermail
5. ↑ "Pointfree - HaskellWiki". https://wiki.haskell.org/Pointfree#But_pointfree_has_more_points.21.

## External links

* Pure Functions in APL and J How to use tacit programming in any APL-like language
* Closed applicative languages 1971 - 1976 ff, in John W. Backus (Publications)

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Tacit programming. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Tacit_programming&oldid=2235828"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template