Download Functional Programming

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Anonymous function wikipedia , lookup

Lambda calculus wikipedia , lookup

Closure (computer programming) wikipedia , lookup

Combinatory logic wikipedia , lookup

Currying wikipedia , lookup

Lambda lifting wikipedia , lookup

Falcon (programming language) wikipedia , lookup

Lambda calculus definition wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Standard ML wikipedia , lookup

Transcript
Some Functional
Programming Languages
• First FP language: IPL (Information Processing Language, 1955).
• First language based on λ-calculus: Lisp (LISt Processing, 1958).
• Two main dialects of Lisp: Scheme (1970) and Common Lisp
(1984).
• First typed functional language: ML (MetaLanguage, 1973).
• Two main dialects of ML: Caml (Categorical Abstract Machine
Language, 1985) and Standard ML (1990).
• Object-oriented version of Caml: OCaml (Objective Caml, 1996).
• Another ML-based multiparadigm language: F# (2005).
• Further functional languages: Miranda (1985), Clean (1987),
Haskell (1990).
Functional Programs
• A program is made up of
•
•
•
•
type declarations / definitions
class declarations / definitions
function declarations / definitions
initial expression
• Running a program: evaluating the initial
expression.
Rewriting (Reduction) System
• Evaluation means rewriting (reducing) the reducible
expression (redex) by textual substitution.
• The exact semantics of reduction steps is
determined by the language model.
• An expression is in normal form if it cannot be
further reduced. It is the result of the evaluation.
• Confluent reduction system: the evaluation order
of subexpressions has no effect on the normal
form. However, the evaluation order may have an
influence on whether the normal form can be
achieved.
Functional vs. Imperative
Programming
• Mathematical foundation: mostly λ-calculus (instead of
Turing machines).
• Programs describe what the problem is, not how to
solve it.
• Programs are stateless, immutable data and data
structures are used (e.g., constants instead of variables,
or lists instead of arrays).
• There are no side effects, programs are referentially
transparent.
• There are no statements, computation is given by
expressions, mainly function calls.
• Recursion has a distinguished role.
Referential Transparency
• Each expression can be replaced with its value
without changing the behavior of the program.
• There is no distinction between a reference to a
thing and the thing itself (e.g., call-by-value and
call-by-reference are the same).
• The order in which expressions are evaluated is not
important; neither is the place of their occurrence
in the source code.
• The program will yield the same output on the
same input in any evaluation order: deterministic.
Additional Features of
Functional Programming
• Higher-order functions (functionals or functors): functions that
take functions as arguments or return a function.
• Function composition: application of one function to the result of
another to produce a third function.
• Currying: transform a function with multiple arguments into a
chain of single-argument functions.
• Partial function application: apply only a subset of the arguments
of a curried function (from left to right) to yield another function
taking the remaining arguments.
• Reduction order: eager (reduce the leftmost innermost redex) vs.
lazy (reduce the leftmost outermost redex).
• Pattern matching: variable binding, parameter passing, match
expressions, etc.
• Off-side rule: blocks are expressed by their indentation (as
opposed to free-form languages).
About F#
• An open-source, cross-platform, functional-first
(multiparadigm) programming language.
• Developed by: Microsoft, F# Software Foundation
(founded in 2013), and open contributors.
• Based on OCaml (based on ML), influenced by: C#,
Python, Haskell, Scala, Erlang.
• History:
•
•
•
•
•
F# 1.0: 2005 (.NET 1.0 – 3.5, VS2005)
F# 2.0: 2010 (.NET 2.0 – 4.0, VS2010, first supported version)
F# 3.0: 2012 (.NET 2.0 – 4.5, VS2012)
F# 3.1: 2013 (.NET 2.0 – 4.5, VS2013)
F# 4.0: 2015 (.NET 2.0 – 4.6, VS2015)
• Home page: http://fsharp.org