Theoretical Underpinnings




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




e→x              variable
  e1 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)




 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)




 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,




  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




  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.




  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.




  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.




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




     No side effects.
     Higher-order functions.




 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.




 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.




 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.




 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 functional
programming languages. ACM Computing Surveys 21, 3 (September
1989), 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

Functional Concepts

  • 2.
    Theoretical Underpinnings Michal P´se(CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 2 / 10
  • 3.
    Lambda Calculus e→x variable e1 e2 application λx.e abstraction Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 3 / 10
  • 4.
    Semantics of LambdaCalculus λxi .e ⇒ λxj .[xj /xi ]e iff xj is not free in e (α-conversion, renaming) Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 4 / 10
  • 5.
    Semantics of LambdaCalculus λxi .e ⇒ λxj .[xj /xi ]e iff xj is not free in e (α-conversion, renaming) (λx.e1 )e2 ⇒ [e2 /x]e1 (β-conversion, application) Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 4 / 10
  • 6.
    Semantics of LambdaCalculus λ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
  • 7.
    Computational Strength ofLambda Calculus Lambda calculus has the same strength as Turing machine. In particular, you can define functions that represent numbers, Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 5 / 10
  • 8.
    Computational Strength ofLambda Calculus Lambda calculus has the same strength as Turing machine. In particular, you can define functions that represent numbers, booleans and conditions and Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 5 / 10
  • 9.
    Computational Strength ofLambda 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
  • 10.
    Functional Languages Michal P´se(CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 6 / 10
  • 11.
    Basic Characteristics No statements, just functions. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 7 / 10
  • 12.
    Basic Characteristics No statements, just functions. Immutable variables. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 7 / 10
  • 13.
    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
  • 14.
    Composability No side effects. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10
  • 15.
    Composability No side effects. Higher-order functions. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10
  • 16.
    Composability No side effects. Higher-order functions. Currying. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 8 / 10
  • 17.
    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
  • 18.
    Evaluation Order Non-strict (lazy) evaluation, possibly infinite data structures. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 9 / 10
  • 19.
    Evaluation Order Non-strict (lazy) evaluation, possibly infinite data structures. Parallel execution. Michal P´se (CTU in Prague) ıˇ Object Prgrmmng L. 3: Functional Concepts October 12, 2010 9 / 10
  • 20.
    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
  • 21.
    See Hudak, P. Conception,evolution, and application of functional programming languages. ACM Computing Surveys 21, 3 (September 1989), 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