Functional Concepts

Post on 26-May-2015

506 views 0 download

Transcript of Functional Concepts

Theoretical Underpinnings

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 2 / 10

Lambda Calculus

e → x variablee1 e2 applicationλx .e abstraction

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 3 / 10

Semantics of Lambda Calculus

λxi .e ⇒ λxj .[xj/xi ]e iff xj is not free in e (α-conversion, renaming)

(λx .e1)e2 ⇒ [e2/x ]e1 (β-conversion, application)

λx .(e x) ⇒ e iff x is not free in e (η-conversion)

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 4 / 10

Semantics of Lambda Calculus

λxi .e ⇒ λxj .[xj/xi ]e iff xj is not free in e (α-conversion, renaming)

(λx .e1)e2 ⇒ [e2/x ]e1 (β-conversion, application)

λx .(e x) ⇒ e iff x is not free in e (η-conversion)

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 4 / 10

Semantics of Lambda Calculus

λxi .e ⇒ λxj .[xj/xi ]e iff xj is not free in e (α-conversion, renaming)

(λx .e1)e2 ⇒ [e2/x ]e1 (β-conversion, application)

λx .(e x) ⇒ e iff x is not free in e (η-conversion)

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 4 / 10

Computational Strength of Lambda Calculus

Lambda calculus has the same strength as Turing machine. In particular,you can define functions that represent

numbers,

booleans and conditions and

recursive computations.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 5 / 10

Computational Strength of Lambda Calculus

Lambda calculus has the same strength as Turing machine. In particular,you can define functions that represent

numbers,

booleans and conditions and

recursive computations.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 5 / 10

Computational Strength of Lambda Calculus

Lambda calculus has the same strength as Turing machine. In particular,you can define functions that represent

numbers,

booleans and conditions and

recursive computations.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 5 / 10

Functional Languages

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 6 / 10

Basic Characteristics

No statements, just functions.

Immutable variables.

No implicit state.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 7 / 10

Basic Characteristics

No statements, just functions.

Immutable variables.

No implicit state.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 7 / 10

Basic Characteristics

No statements, just functions.

Immutable variables.

No implicit state.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 7 / 10

Composability

No side effects.

Higher-order functions.

Currying.

Pattern matching.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10

Composability

No side effects.

Higher-order functions.

Currying.

Pattern matching.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10

Composability

No side effects.

Higher-order functions.

Currying.

Pattern matching.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10

Composability

No side effects.

Higher-order functions.

Currying.

Pattern matching.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10

Evaluation Order

Non-strict (lazy) evaluation, possibly infinite data structures.

Parallel execution.

Memoization.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 9 / 10

Evaluation Order

Non-strict (lazy) evaluation, possibly infinite data structures.

Parallel execution.

Memoization.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 9 / 10

Evaluation Order

Non-strict (lazy) evaluation, possibly infinite data structures.

Parallel execution.

Memoization.

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 9 / 10

See

Hudak, P. Conception, evolution, and application of functionalprogramming languages. ACM Computing Surveys 21, 3 (September1989), 359–411. http://doi.acm.org/10.1145/72551.72554

Michal Pıse (CTU in Prague) Object Prgrmmng L. 3: Functional Concepts October 12, 2010 10 / 10