130 likes | 256 Views
Mathematical Foundations. Supplemental material – not on exam. Lambda Calculus. From wikipedia.
E N D
Mathematical Foundations Supplemental material – not on exam
From wikipedia • Lambda calculus (also written as λ-calculus) is a formal system in mathematical logic and computer science for expressing computation based on function abstraction and application using variable binding and substitution. • In other words, this formalizes the concept of a function applied to arguments, so that we can reason about it • Name derives from the Greek letter lambda (λ) used to denote binding a variable in a function. http://en.wikipedia.org/wiki/Lambda_calculus
Why? Computability theory • Computability is the ability to solve a problem in an effective manner. • Alonzo Church used lambda calculus to formalize the concept of effective computability. • Lambda calculus has been shown to have computationally equivalent power to Turing computability (Church-Turing thesis) • Lambda calculus is considered by some to be the world’s first programming language, although it is really intended to modelcomputation rather than to describe algorithms. • Stack, Environment, Control, Dump (SECD) machine proposed as an abstract machine intended as a target for functional programming language compilers. • LISP and other functional programming languages essentially implement the calculus.
Main ideas • Lambda calculus is a simple notation for functions and application • Main ideas: • Applying a function to an argument • Forming functions by abstraction • What is a function? • Extensional view: sets of ordered pairs. (1,1),(2,8),(3,9),(4,16) • Intensional view: rules of computation From http://plato.stanford.edu/entries/lambda-calculus/
Language Syntax* • Lambda expressions are composed (the language alphabet) of • variables v1, v2, ..., vn, ... • the abstraction symbols lambda 'λ' and dot '.' • parentheses ( ) • The set of lambda expressions, Λ, can be defined inductively: • If x is a variable, then x ∈ Λ • If x is a variable and M ∈ Λ, then (λx.M) ∈ Λ • If M, N ∈ Λ, then (M N) ∈ Λ • Instances of rule 2 are known as abstractions and instances of rule 3 are known as applications. • Slightly different notations can be found, this is from wikipedia
What is a monad? • From: • http://en.wikipedia.org/wiki/Monads_in_functional_programming • http://stackoverflow.com/questions/44965/what-is-a-monad • Monad is a structure that represents computations defined as sequences of steps • A type with a monad structure defines what it means to chain operations • Ex: [x*2 | x<-[1..10], odd x] • operation returns a list • following operations performed on every item of the list
Mathematical Definition • From wikipedia: • branch of mathematics called category theory • monad is triple: functor + 2 natural transformations • functional programming monads correspond to strong monads in category theory
Monadic type • A monad consists of a type constructor M and two operations, bind and return • returntakes a plain value and uses the constructor to place it in a monadic container, thus creating a monadic value • binddoes the reverse: extracts the value from the container and passes it to the next function in the pipeline What does this sound like?