COSC 5 V 90 Functional Programming and Interactive

  • Slides: 5
Download presentation
COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Imperative languages •

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Imperative languages • • • Von Neumann model: – store with addressable locations machine code: – effect achieved by changing contents of store locations – instructions executed in sequence, flow of control altered by jumps imperative language: – variable corresponds to store location – instructions executed in sequence, flow of control altered by conditional and loop statements – efficient implementation since close to design of conventional computers © M. Winter 1. 1

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Functional languages •

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Functional languages • • computational model: lambda calculus mathematical functions: domain, range functional languages achieve effect by applying functions functional vs. imperative languages – store location – assignment statement vs. application of a function (expressions) • side-effects • aliasing • referential transparency © M. Winter 1. 2

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Features of functional

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Features of functional languages • • usually strongly typed (modern languages) algebraic type definitions – mathematical based notation – no (implicit) pointers higher-order functions – can accept functions as parameters – can return functions as results recursion as a basic principle application of rewrite rule: – function call replaced by code body run-time overhead garbage collection slogan: define “what to do”, not “how to do” © M. Winter 1. 3

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Lambda Calculus The

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Lambda Calculus The λ-calculus is a system to define and execute function. We will have a brief look at the simply typed λ-calculus. 1. Formation rules. Let X be a set of variables. – t : A should be read as “t has type A” – Γ |- t : A where Γ is a sequence of x : A with x X. The statement should be read as “Assuming that the variable x has type A for all x : A Γ, then t has type A. ” Axiom: Γ |- x : A if x : A Γ Rules: Γ, x : A |- t : B Γ |- λx: A. t : A→B Γ |- f : A→B Γ |- t : A Γ |- (f t) : B © M. Winter 1. 4

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Lambda Calculus 2.

COSC 5 V 90 – Functional Programming and Interactive Theorem Proving Lambda Calculus 2. Execution rules: β-reduction: (λx: A. t 1 t 2) t 1[t 2/x] Context rules: t 1 t 2 λx: A. t 1 λx: A. t 2 t 1 t 2 t 3 t 4 (t 1 t 3) (t 2 t 4) © M. Winter 1. 5