FP trivia
FP trivia is a pointfree programming language^{[1]}^{[2]} inspired by FP of John Backus, APL, Smalltalk and Lisp. It is intended to remedy the problematic fact that FP^{[3]} is viewed as free of variables,^{[4]}^{[5]}^{[6]} which is also true in terms of lambda variables, but not in terms of the instance variables that are used by FP trivia.^{[7]} The main data type is therefore a table that the instance variables can access. It should not be forgotten that one motivation for creating FP was the use of an "Algebra of Programming".^{[8]}^{[9]}
Syntax
A table is a linear arrangement of key–value pairs similar to a linked list.
( value0 key0 value1 key1 value2 key2 ... ... valuen keyn )
An instance variable can then access a certain key and pick out the associated value.
#key1 : (value0 key0 value1 key1 value2 key2 ... ... valuen keyn) --> value1
In the original FP by John Backus, it was only possible to access values in a sequence using numbers as selectors. This is still possible via integer numbers on the values in the table.
[2] : (value0 key0 value1 key1 value2 key2 ... ... valuen keyn) --> value2
So you can define a function that adds three numbers.
triadd == (#a + #b + #c) <- a;b;c;
triadd ° 10,20,30, --> 60
Algebra of Programming
The programs are in the arithmetic expression tree structure mentioned above and can be changed using algebraic rules. (A right-associativity must be observed)
f == id * id g == id + 1
p == (2*id) * (f + g) == (2*id*f) + (2*id*g) == (2*id*g) + (2*id*f) == (g*id*2) + (f*id*2) // etc
Program Combinators are used in Infix Notation
Combinator | Form | ||
---|---|---|---|
Constant | 'x | = x | = x |
Application | f : x | = f(x) | = r |
Composition | (f o g) : x | = f(g(x)) | = r |
Construction | (f_{1} , f_{2} , ... , f_{n} ,) : x | = (f_{1}:x) , (f_{2}:x) , ... , (f_{n}:x) , | = (r_{1} ; r_{2} ; ... ; r_{n} ;) |
Condition | (f -> g | h) : x | = if (f:x) then (g:x) else (h:x) | = r |
While-Loop | (f ->* g) : x | = while (f:x) do new x = (g:x) | = r |
Apply-to-All | (f aa) : (x_{1} ; x_{2} ; ... ; x_{n} ;) | = (f:x_{1}) , (f:x_{2}) , ... (f:x_{n}) , | = (r_{1} ; r_{2} ; ... ; r_{n} ;) |
Insertr | (f \) : (x_{1} ; x_{2} ; ... ; x_{n} ;) | = f:(x_{1} ; f:(x_{2} ; f:(... ; f:(x_{n-1} ; x_{n} ;) ;) ;) ;) | = r |
Eval-Eval | (f ee g) : x | = (f:x) , (g:x) , | = (r_{1} ; r_{2} ;) |
Apply | (f app g) : x | = apply(f(x),g(x)) | = r |
New infix combinators can be built with the functions term and arg and the existing functions and combinators.^{[10]}
Instance variables with type test predicates
In order to achieve better type security for the instance variables, there is the option of type testing with predicates.
triadd == (#a + float°(#b + round°#c)) <- a isreal b isint c isnum
triadd ° 10,'[20],30, --> 60
triadd ° 10,20,30, --> Exception... Typemismatch
External links
References
- ↑ Pointfree - HaskellWiki. Retrieved on 5. Jan. 2021
- ↑ Point-free Program Calculation by Manuel Alcino Pereira da Cunha
- ↑ "Can programming be liberated from the von Neumann style?: A functional style and its algebra of programs" Communications of the ACM. 21 (8): 613.
- ↑ Closed applicative languages 1971 - 1976 ff in John W. Backus (Publications)
- ↑ Why did John Backus' function-level programming paradigm (...) never catch on?
- ↑ Obfuscation - HaskellWiki. Retrieved on 5. Jan. 2021
- ↑ Progopedia Example with instance variables
- ↑ Richard Bird and Oege de Moor: Algebra of Programming. Prentice Hall Europe, 1997.
- ↑ The Algebra of Programming on Medium
- ↑ J. Gibert 1987 Functional Programming with Combinators