22-lambda - Programming Language Features CMSC 330...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 2 Programming Language Features Many features exist simply for convenience • Multi-argument functions foo ( a, b, c ) Use currying or tuples • Loops while (a < b) … Use recursion • Side effects a := 1 Use functional programming So what language features are really needed? CMSC 330 3 Turing Completeness Computational system that can • Simulate a Turing machine • Compute every Turing-computable function A programming language is Turing complete if • It can map every Turing machine to a program • A program can be written to emulate a Turing machine • It is a superset of a known Turing-complete language Most powerful programming language possible • Since Turing machine is most powerful automaton CMSC 330 4 Programming Language Theory Come up with a “core” language • That’s as small as possible • But still Turing complete Helps illustrate important • Language features • Algorithms One solution • Lambda calculus CMSC 330 5 Lambda Calculus ( -calculus) Proposed in 1930s by • Alonzo Church • Stephen Cole Kleene Formal system • For exploration of foundations of mathematics Now used as • Tool for investigating computability • Basis of functional programming languages Lisp, Scheme, ML, OCaml, Haskell… CMSC 330 6 Lambda Expressions A lambda calculus expression is defined as e ::= x variable | x.e function | e e function application x.e is like (fun x -> e) in OCaml That’s it! Nothing but higher-order functions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 CMSC 330 7 Three Conveniences Syntactic sugar for local declarations • let x = e1 in e2 is short for ( x.e2) e1 Scope of extends as far right as possible • Subject to scope delimited by parentheses x. y.x y is same as x.( y.(x y)) Function application is left-associative • x y z is (x y) z • Same rule as OCaml CMSC 330 8 Lambda Calculus Semantics All we’ve got are functions • So all we can do is call them To evaluate ( x.e1) e2 • Evaluate e1 with x bound to e2 This application is called beta-reduction • ( x.e1) e2 e1[x/e2] e1[x/e2] is e1 where occurrences of x are replaced by e2 Slightly different than the environments we saw for Ocaml
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2012 for the course CMSC 330 taught by Professor Staff during the Fall '08 term at Maryland.

Page1 / 6

22-lambda - Programming Language Features CMSC 330...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online