HOME

TheInfoList



OR:

Tacit programming, also called point-free style, is a
programming paradigm A programming paradigm is a relatively high-level way to conceptualize and structure the implementation of a computer program. A programming language can be classified as supporting one or more paradigms. Paradigms are separated along and descri ...
in which function definitions do not identify the
arguments An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
(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.Manuel Alcino Pereira da Cunha (2005
Point-free Program Calculation
/ref> It is also the natural style of certain
programming languages A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their syntax (form) and semantics (meaning), usually defined by a formal language. Languages usually provide features ...
, including APL and its derivatives, and concatenative languages such as Forth. The lack of argument naming gives point-free style a reputation of being unnecessarily obscure, hence the
epithet An epithet (, ), also a byname, is a descriptive term (word or phrase) commonly accompanying or occurring in place of the name of a real or fictitious person, place, or thing. It is usually literally descriptive, as in Alfred the Great, Suleima ...
"pointless style".
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
scripting uses the paradigm with
pipes Pipe(s), PIPE(S) or piping may refer to: Objects * Pipe (fluid conveyance), a hollow cylinder following certain dimension rules ** Piping, the use of pipes in industry * Smoking pipe ** Tobacco pipe * Half-pipe and quarter pipe, semi-circu ...
.


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))) ... can be written in point-free style as the composition of a sequence of functions, without parameters: 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 can be translated as: p = partial(compose, partial(compose, f), g)


Functional programming

A simple example (in
Haskell Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...
) 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 (higher-order function), 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 In mathematics, the composition operator \circ takes two function (mathematics), functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is function application, applied after applying to . (g \c ...
: 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 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. 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 Euler's formula, named after Leonhard Euler, is a mathematical formula in complex analysis that establishes the fundamental relationship between the trigonometric functions and the complex exponential function. Euler's formula states that, for ...
e^ = \cos x + i\sin x, 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 APL_(programming_language)#Dyalog_APL, 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 number In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
s might look like the following in
PostScript PostScript (PS) is a page description language and dynamically typed, stack-based programming language. It is most commonly used in the electronic publishing and desktop publishing realm, but as a Turing complete programming language, it c ...
: /fib def


Pipelines


Unix pipeline

In Unix scripting the functions are computer programs which receive data from
standard input In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), ...
and send the results to
standard output Standard may refer to: Symbols * Colours, standards and guidons, kinds of military signs * Standard (emblem), a type of a large symbol or emblem used for identification Norms, conventions or requirements * Standard (metrology), an object t ...
. 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 descriptor In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically h ...
s can be opened from named pipes, this no longer constitutes a point-free style.


jq

jq is a JSON-oriented programming language in which the ', ' symbol is used to connect filters to form a pipeline in a familiar way. For example: ,2, add evaluates to 3. (Yes, the JSON array is a jq filter that evaluates to an array.) Although similar to Unix pipelines, jq pipelines allow the incoming data to be sent to more than one recipient on the RHS of the ', ' as though in parallel. For example, the program `add/length` will compute the average of the numbers in an array, so that: ,2, add/length evaluates to 1.5 Similarly: ,2, ength, add, add/length evaluates to ,3,1.5 A dot ('.') can be used to define an attachment point on the RHS, e.g.: 1 , , . evaluates to ,1 and similarly: 2 , pow(.; .) evaluates to 4 since pow(x;y) is x to the power y.


=Fibonacci sequence

= A tacit jq program for generating the Fibonacci sequence would be: ,1, recurse( ast, add) , first Here, ,1is the initial pair to be taken as the first two items in the Fibonacci sequence. (The pair ,1could likewise be used for the variant definition.) The alphabetic tokens are built-in filters: `first` and `last` emit the first and last elements of their input arrays respectively; and `recurse(f)` applies a filter, f, to its input recursively. jq also allows new filters to be defined in a tacit style, e.g.: def fib: ,1, recurse( ast, add) , first;


=Composition of unary functions

= In the section on Python in this article, the following Python definition is considered: def example(x): return baz(bar(foo(x))) In point-free style, this could be written in Python as: example = compose(foo, bar, baz) In jq, the equivalent point-free definition would be: def example: foo , bar , baz;


See also

*
Combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
* Concatenative programming language *
Function-level programming In computer science, function-level programming refers to one of the two contrasting programming paradigms identified by John Backus in his work on programs as mathematical objects, the other being value-level programming. In his 1977 Turin ...
*
Joy (programming language) The Joy programming language in computer science is a purely functional programming language that was produced by Manfred von Thun of La Trobe University in Melbourne, Australia. Joy is based on composition of functions rather than lambda calcul ...
, modern highly tacit language


References


External links


From Function-Level Programming to Pointfree Style

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) {{Programming paradigms navbox Programming paradigms