1 / 11

CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha

CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha. Functional Languages. Functional Programming. Models a program as a mathematical function mapping the inputs to the outputs. Avoids the notion of state and mutable data, and therefore has no side effects.

Download Presentation

CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 330: Programming Language ConceptsInstructor: Pranava K. Jha Functional Languages

  2. Functional Programming • Models a program as a mathematical function mapping the inputs to the outputs. • Avoids the notion of state and mutable data, and therefore has no side effects. • Has declarative flow of control; promotes function composition instead of statement composition. • Influenced by lambda calculus.

  3. Historical Origins • The functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. during 1930s. • Different formalizations of the notion of an algorithm, or effective procedure, based on automata, symbolic manipulation, recursive function definitions, and combinatorics. • These results led Church to conjecture that any intuitively appealing model of computing would be equally powerful as well. • This conjecture is known as Church’s thesis.

  4. Historical Origins • Church’s model of computing is called the lambda calculus. • Based on the notion of parameterized expressions (with each parameter introduced by an occurrence of the letter λ—hence the notation’s name. • Lambda calculus was the inspiration for functional programming. • One employs it to compute by substituting parameters into expressions, just as one computes in a high-level functional program by passing arguments to functions.

  5. Functional Programming Concepts • Functional languages such as Lisp, Scheme, FP, ML, Miranda, and Haskell are an attempt to realize Church's lambda calculus in practical form as a programming language • Key idea: Do everything by composing functions. • no mutable state • no side effects

  6. Concepts in Functional Programming • First-class function values and higher-order functions • Extensive polymorphism • List types and operators • Recursion • Structured function returns • Constructors (aggregates) for structured objects • Garbage collection

  7. Constructs in Functional Programming • Building blocks are functions. • No statement composition, but function composition. • No variable assignments, but a local variable can be bound to a single value. • No loops, but recursion. • Conditional flow with if-then-else or input patterns.

  8. Examples from Haskell gcd a b | a == b = a | a > b = gcd (a-b) b | a < b = gcd a (b-a) fact 0 = 1 fact n = n * fact (n-1)

  9. Recursion does a nifty job of replacing looping becomes

  10. Functional Programming Concepts • Pure Lisp is purely functional; all other Lisps have imperative features • All early Lisps dynamically scoped • Not clear whether this was deliberate or if it happened by accident • Scheme and Common Lisp statically scoped • Common Lisp provides dynamic scope as an option for explicitly-declared special functions • Common Lisp now THE standard Lisp • Very big; complicated (The Ada of functional programming)

  11. Functional Programming Concepts • Scheme is a particularly elegant Lisp • Other functional languages • ML • Miranda • Haskell • FP • Haskell is the leading language for research in functional programming.

More Related