Functional Concepts

21

Transcript of Functional Concepts

Page 1: Functional Concepts
Page 2: Functional Concepts

Theoretical Underpinnings

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

Page 3: Functional Concepts

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

Page 4: Functional Concepts

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

Page 5: Functional Concepts

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

Page 6: Functional Concepts

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

Page 7: Functional Concepts

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

Page 8: Functional Concepts

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

Page 9: Functional Concepts

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

Page 10: Functional Concepts

Functional Languages

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

Page 11: Functional Concepts

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

Page 12: Functional Concepts

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

Page 13: Functional Concepts

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

Page 14: Functional Concepts

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

Page 15: Functional Concepts

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

Page 16: Functional Concepts

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

Page 17: Functional Concepts

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

Page 18: Functional Concepts

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

Page 19: Functional Concepts

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

Page 20: Functional Concepts

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

Page 21: Functional Concepts

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