Declarative Paradigm contains 2 programming languages: 1.
Functional Programming
2.
Functional Programming
Summarize your findings with citations
Present 2 examples of programming language each for the branches
Logic Programming (online) = ISSN 2285 – 3642
ISSN-L = 2285 – 3642
Journal of Economic Development, Environment and People
Volume 4, Issue 4, 2015
URL: http://jedep.spiruharet.ro
e-mail: office_jedep@spiruharet.ro
Functional Programming Using the New C++ Standard
Radu BUCEA-MANEA-ȚONIȘ1, Rocsana ȚONIȘ (BUCEA-MANEA)2
Abstract. In our article we demonstrate that the new C++ standard is the one preferred by economists and
big software companies to implement AI and decision making algorithms. Today software technology
evolves very quickly, to an old paradigm, called functional programming. This paradigm uses lambda
functions ready to be used where declared instead of function pointers. The long term target is to let
compilers evaluate rather than execute a program/function. The new C++14 standard allows lambda
calculus as we demonstrate in the applicative section of implementing conditionals, booleans and numbers.
Keywords: lambda, combinator, predicate, stochastic neoclassical growth model.
JEL Codes: M15
1.
Introduction
As Phil Johnson stated, economists have to write code in order to run and evaluate their complex
mathematical models and simulations. They want to improve their functional skills by understanding
lambda calculus and improve de efficiency of programs by making them semantically transparent. A
common approach to improve semantics of a programming language involves a translation of a given
language into a language that represents labels and jumps as functions [Komendantsky, 2009]. Semantics
gives meaning to a language, by assigning mathematical objects as values to its terms, that might be easily
done using the new C++14 standard.
Extending functionality using callback functions is one of the goals of functional
programming.[Pouliasis, 2014] After a literature review, in articles and archives available on international
databases, such as Web of Science, EBSCOhost, IS journals and IS conference proceedings we found out
that in near future might be possible to let compiler evaluate rather than execute a program. The
evaluation may involve making calls to external resources and eventually receiving answers from such calls,
so that the internal evaluation can proceed [AlTurki, 2015]. In our article we demonstrate how the newly
C++14 standard can be used in functional programming by implementing conditionals, booleans and
numbers.
1
PhD., Coordinator for Open source MySQL Browser for Windows https://mysqlbrowser.codeplex.com/, Stefanini
Romania, e-mail: radub_m@yahoo.com
2
Spiru Haret university, PhD Candidate, University Politehnica of Bucharest, Romania, e-mail: rocsense39@yahoo.com
58
(online) = ISSN 2285 – 3642
ISSN-L = 2285 – 3642
Journal of Economic Development, Environment and People
Volume 4, Issue 4, 2015
URL: http://jedep.spiruharet.ro
e-mail: office_jedep@spiruharet.ro
Implementing the stochastic neoclassical growth model, the workhorse of modern macroeconomics in
C++11, results that C++ compilers have advanced enough that, contrary to the situation in the 1990s and
some folk wisdom, C++ code runs slightly faster (5-7 percent) than Fortran code. [Borağan, 2014]
After [Hughes, 1990], using higher-order functions and lazy evaluation one can modularize programs in
new and useful ways, gluing functions together, gluing programs together, and thus making functional
programming languages appropriate for building AI applications.
D.Syme found that functional programming is simple, efficient and fun to work with, making worth by
Microsoft to invest in F#, a programming language influenced by C# and OCAML, having orthogonal &
unified constructs [Syme, 2008]
2.
Research methodology:
The research methodology consists of the literature study with the focus on the C++14 standard that
allow implementation of lambda calculus. Our study has 3 steps:
1. Choosing databases to search articles, archives and scratch. In this respect we have chosen Web of
Science, EBSCOhost, IS journals and IS conference proceedings;
2. Screening papers and extracting information that might be transformed in knowledge. There have
been chosen especially new articles. For the selection we asked several keywords, such as: lambda calculus,
functional programming, etc.;
3. Using C++14 standard we made small implementations of lambda calculus, such as combinators,
conditionals, booleans and numbers.
3.
Literature review
In the nineteen century we assist at the reborn of logic at such magnitude that no one had seen it
before for 2000 years. First steps where done by G. Boole (1815-1864) that define a new branch of
mathematics based on a couple of truth functions (future operators) defined on a set made by only two
values: true and false (0 and 1). [Rojas, 1998]
Further on, important steps were made in formal logic starting with G.Frege (1848-1925) proposing
predicate logic to reveal underneath layers of propositional logic through analytic methods, continuing
with B.Russel (1872-1970) and A.N.Whitehead (1861-1947) trying to set mathematics on logical based
ground (Principia Mathematica).
Another valuable direction in logic is combinatory logic with the contributions of M.I. Schönfinkel
(1889-1942) that introduced logical combinators (e.g. I, K, S) that could be used to represent any logical
expression and H.Curry (1900-1982) credited for the currying method used for the transformation of logical
expressions.
59
(online) = ISSN 2285 – 3642
ISSN-L = 2285 – 3642
Journal of Economic Development, Environment and People
Volume 4, Issue 4, 2015
URL: http://jedep.spiruharet.ro
e-mail: office_jedep@spiruharet.ro
G. Boole (1815-1864)
1864)
M.I. Schönfinkel (1889-1942)
A.Church(1903-1995)
1995)
After the cold shower provided by the Russel Paradox and K.Gödel(1906-1978)
K.Gödel(1906
Incompleteness
Theorem, A.Church(1903-1995)
1995) proposed lambda calculus as an alternative computing model for A.Turing
(1912-1954)
1954) Automata, that served as base for the next generation of functional programming languages.
Lambda calculus
4.
Lambda calculus is a theory of computable functions that focuses on evaluation of expressions
resulted from applying functions to other expressions. An expression could be made from another function
(abstraction), bound/unbound variables and it is evaluated from left to right. Not everything that looks like
a function fits obviously into the λ-calculus;
λ
examples
amples include metavariables, capturing substitution, and
functions depending on intensional properties like free variables [Gabbay, 2009]. There are only two
operators: λ that precedes an abstraction and. (dot) operator that precedes any expressions the function
f
is
applied to. Round parentheses are used for grouping terms but they have no meaning. There is typed and
un-typed
typed lambda calculus but we prefer the first for the sake of simplicity.
One example of lambda expression is the following:
λx.λy.λz.x y z
(1)
, and using curried notation, we obtain:
λxyz.x y z
(2)
4.1.
Combinators
There are few combinators that help us write more concise lambda expressions:
1.
Identity combinator:
I = λx.x → x
(3)
2.
Constant combinator:
K = λx.k → k
(4)
3.
The substitution combinator:
S = λxyz.xz(zy)
(5)
60
(online) = ISSN 2285 – 3642
ISSN-L = 2285 – 3642
Journal of Economic Development, Environment and People
Volume 4, Issue 4, 2015
URL: http://jedep.spiruharet.ro
e-mail: office_jedep@spiruharet.ro
4.2
Conditionals
For introducing a condition we introduce the pair structure which takes two false/true expressions
and one predicate function that says what value to return: the first, or the second [Kieras, 2015]:
λx.λy.λf(f x y)
(6)
, where
TRUE ← λx.λy.x
(7)
, and
FALSE ← λx.λy.y
(8)
One possible C++ implementation of lambda conditional function will be:
auto IF = [] (auto f, int a, int b) {return f(a,b);};
(9)
, where the predicate function may be:
auto TRUE= [] (int x,int y) {return x;};
(10)
, and
auto FALSE= [] (int x,int y) {return y;};
(11)
In C++11, lambda function parameters need to be declared with concrete types. C++14 relaxes this
requirement, allowing lambda function parameters to be declared with the auto type specifier.
For example, the line:
std::cout