1-1 An Introduction to Functional Programming Sept. 2008.

Slides:



Advertisements
Similar presentations
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
Functional Programming Languages
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
ISBN Chapter 15 Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages Introduction to.
Programming Languages Structure
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Programming Language Theory Leif Grönqvist The national Graduate School of Language Technology (GSLT) MSI.
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
ISBN Chapter 15 Functional Programming Languages.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
1 Lisp and Functional Languages Functional forms Referential transparency Function construction Function composition Mapping functions Designing functional.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
CS 355 – Programming Languages
0 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
1 Functional Programming In Text: Chapter Chapter 2: Evolution of the Major Programming Languages Outline Functional programming (FP) basics A bit.
 The design of the imperative languages is based directly on the von Neumann architecture  Efficiency is the primary concern  Low-level specifications:
ISBN Chapter 15 Functional Programming Languages.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Common LISP A combination of many of the features of the popular dialects of LISP around in the early 1980s A large.
ISBN Chapter 15 Functional Programming Languages.
1 Programming Languages and Paradigms Functional Programming.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
Chapter Fifteen: Functional Programming Languages Lesson 12.
ISBN Chapter 15 Functional Programming Languages.
CS 363 Comparative Programming Languages Functional Languages: Scheme.
Comparative Programming Languages Language Comparison: Scheme, Smalltalk, Python, Ruby, Perl, Prolog, ML, C++/STL, Java, Haskell.
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
ISBN Chapter 15 Functional Programming Languages.
1 Chapter 15 © 2002 by Addison Wesley Longman, Inc Introduction - The design of the imperative languages is based directly on the von Neumann architecture.
ISBN Chapter 15 Functional Programming Languages.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Functional Programming Part 1. Organization of Programming Languages-Cheng Big Picture u What we’ve learned so far: Imperative Programming Languages 
ISBN Chapter 15 Functional Programming Languages.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
ISBN Chapter 15 Functional Programming Languages.
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Functional Programming
Functional Programming
Functional Programming Languages
Functional Programming Languages
Chapter 15 :Functional Programming Languages
Functional Programming Languages
Functional Programming
History of Computing – Lisp
PROGRAMMING LANGUAGES
Functional Programming
Functional Programming Languages
Fundamentals of Functional Programming Languages
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
Programming Languages 2nd edition Tucker and Noonan
Functional Programming Languages
15.2 Mathematical Functions
Chapter 15 Functional Programming 6/1/2019.
Functional Programming Languages
Presentation transcript:

1-1 An Introduction to Functional Programming Sept. 2008

1-2 Topics Introduction Mathematical Functions Fundamentals of Functional Programming Languages Applications of Functional Languages Comparison of Functional and Imperative Languages The First F P Language: LISP COMMON LISP

1-3 Introduction The design of the imperative languages is based directly on the von Neumann architecture –Efficiency is the primary concern, rather than the suitability of the language for software development The design of the functional languages is based on mathematical functions –A solid theoretical basis that is also closer to the user, but relatively unconcerned with the architecture of the machines on which programs will run

1-4 Introduction (Contd.) What is the Functional Paradigm ? Program viewed as a collection of functions. –Functional programming is a style of programming in which the basic method of computation is the application of functions to arguments; –A functional language is one that supports and encourages the functional style. Functional languages try to model mathematical functions as much as possible. There are no assignments; assignments are bad and therefore banned! Emphasize on simple and clean semantics. Example languages: Scheme, Miranda TM, Haskell, ML

1-5 Introduction (Contd.) The Functional Paradigm: Computational Foundation FLs are based on a computation model called lambda calculus The lambda calculus is a simple mathematical theory developed before the advent of digital computers The lambda calculus was intended to be a foundation of mathematics in the 1930s The lambda calculus has very few syntactic constructs but it is Turing complete –It can compute any function that can be computed by a computing device FLs are often considered as sugared versions of the lambda calculus

1-6 Introduction (Contd.) Functional Languages: Key Features High-level of abstraction –Functional languages are among the highest-level languages in present-day use Clean and simple semantics –Easier to reason about functional programs than imperative programs Conciseness (expressivity) –Support for rapid application development Support for concurrency High orthogonality –Few language constructs compared to imperative or OO languages Lazy evaluation (for some of them)

1-7 Mathematical Functions Def: A mathematical function is a mapping of members of one set, called the domain set, to another set, called the range set A lambda expression specifies the parameter(s) and the mapping of a function in the following form (x) x * x * x for the nameless function f(x) = x * x * x

1-8 Mathematical Functions (Contd.) Lambda expressions describe nameless functions Lambda expressions are applied to parameter(s) by placing the parameter(s) after the expression e.g. ( (x) x * x * x)(3) which evaluates to 27

1-9 Mathematical Functions (Contd.) Def: A higher-order function, or functional form, is one that either takes functions as parameters or yields a function as its result, or both Many kinds of functional forms, here are some: 1. Function Composition –A functional form that takes two functions as parameters and yields a function whose value is the first actual parameter function applied to the result of the second Form: h  f ° g which means h (x)  f ( g ( x)) For f (x)  x * x * x and g (x)  x + 3, h  f ° g → h(x) = f(g(x)) = g(x) * g(x) * g(x) =(x + 3)* (x + 3)* (x + 3)

1-10 Mathematical Functions (Contd.) 2. Construction –A functional form that takes a list of functions as parameters and yields a list of the results of applying each of its parameter functions to a given parameter Form: [f, g] For f (x)  x * x * x and g (x)  x + 3, [f, g] (4) yields (64, 7)

1-11 Mathematical Functions (Contd.) 3. Apply-to-all –A functional form that takes a single function as a parameter and yields a list of values obtained by applying the given function to each element of a list of parameters Form:  For h (x)  x * x * x  ( h, (3, 2, 4)) yields (27, 8, 64)

1-12 Why Functional Languages? The main reason we use functional programming is to reduce the time it takes to bring a product to the market and to reduce the total effort required to design and maintain our products. As functional programs are both shorter and more succinct than corresponding programs in languages such as C, C++, or Java, the number of errors made in the design is also greatly reduced –Ericsson Telecom Widely used for teaching introductory computer science courses in European universities, especially

1-13 Applications of Functional Languages APL is used for throw-away programs LISP is used for artificial intelligence –Knowledge representation –Machine learning –Natural language processing –Modeling of speech and vision Scheme is used to teach introductory programming at a significant number of universities

1-14 Comparing Fun. and Imp. Languages Imperative Languages: –Efficient execution –Complex semantics –Complex syntax –Concurrency is programmer designed Functional Languages: –Simple semantics –Simple syntax –Inefficient execution –Programs can automatically be made concurrent

1-15 The First F P Language: LISP Data object types: originally only atoms and lists List form: parenthesized collections of sublists and/or atoms e.g., (A B (C D) E) Originally, LISP was a typeless language LISP lists are stored internally as single-linked lists Lambda notation is used to specify functions and function definitions. Function applications and data have the same form. e.g., If the list (A B C) is interpreted as data it is a simple list of three atoms, A, B, and C. If it is interpreted as a function application, it means that the function named A is applied to the two parameters, B and C The first LISP interpreter appeared only as a demonstration of the universality of the computational capabilities of the notation

1-16 COMMON LISP A combination of many of the features of the popular dialects of LISP around in the early 1980s A large and complex language--the opposite of Scheme Includes: –records –arrays –complex numbers –character strings –powerful I/O capabilities –packages with access control –imperative features like those of Scheme –iterative control statements