TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.

Slides:



Advertisements
Similar presentations
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
Advertisements

1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 14 Functional Programming Languages - The design of the imperative languages is based directly.
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Functional Programming Language (Introduction and Scheme) Lecture 17 – Functional Programming, Spring.
1 Functional programming Languages And a brief introduction to Lisp and Scheme.
Functional Design and Programming Lecture 1: Functional modeling, design and programming.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
0 PROGRAMMING IN HASKELL Chapter 1 - Introduction.
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
ISBN Chapter 15 Functional Programming Languages Mathematical Functions Fundamentals of Functional Programming Languages Introduction to.
ISBN Chapter 15 Functional Programming Languages.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
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.
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)
Com Functional Programming Higher Order Functions and Computation Patterns (I) Marian Gheorghe Lecture 10 Module homepage Mole &
Haskell Chapter 1, Part I. Highly Recommended  Learn you a Haskell for Great Good. Miran Lipovaca.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
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.
Haskell. 2 GHC and HUGS Haskell 98 is the current version of Haskell GHC (Glasgow Haskell Compiler, version 7.4.1) is the version of Haskell I am using.
Functional Programming Languages Chapter 14
ISBN Chapter 15 Functional Programming Languages.
1 COMP313A Functional Programming (1). 2 Main Differences with Imperative Languages Say more about what is computed as opposed to how Pure functional.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Functional Programming Universitatea Politehnica Bucuresti Adina Magda Florea
CHAPTER 15 & 16 Functional & Logic Programming Languages.
Chapter Fifteen: Functional Programming Languages Lesson 12.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
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.
COMP313A Functional Programming (1)
1 Alex Proctor and Brian Lee for CSCI 431 at UNCA, Fall 2002 ML (Meta Language) a brief introduction Alex Proctor and Brian Lee For CSCI 431 at the University.
1-1 An Introduction to Functional Programming Sept
CS5205Haskell1 CS5205: Foundation in Programming Languages Basics of Functional Programming.
CSE 5317/4305 L12: Higher-Order Functions1 Functional Languages and Higher-Order Functions Leonidas Fegaras.
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 
Haskell Introduction CSCE 314 Spring CSCE 314 – Programming Studio Historical Background 1930s: Alonzo Church develops the lambda calculus, a simple.
Erik Meijer FP101x - Functional Programming Programming in Haskell - Introduction.
1 Introduction to Functional Programming in Racket CS 270 Math Foundations of CS Jeremy Johnson.
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)
Introduction to Functional Programming Part 1 – The Basic Concepts Winter Young
Functional Programming
Programming Languages 2nd edition Tucker and Noonan
Functional Programming
CS 3723 Programming Languages
Functional Programming Languages
What is a Functional Language?
CS 3304 Comparative Languages
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Functional Programming
Functional Programming in a Nutshell with Haskell and F#
Introduction to Functional Programming in Racket
Introduction to the C Language
FP Foundations, Scheme In Text: Chapter 14.
Functional Programming Languages
Programming Languages 2nd edition Tucker and Noonan
Introduction to Functional Programming in Racket
CSE 3302 Programming Languages
PROGRAMMING IN HASKELL
CSE 3302 Programming Languages
COP4020 Programming Languages
15.2 Mathematical Functions
Chapter 15 Functional Programming 6/1/2019.
Presentation transcript:

TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen

TIVDM2Functional Programming Language Concepts 2 Agenda  Introduction to the Functional Programming Paradigm The notion of higher order functions Polymorphic examples of standard higher order functions

TIVDM2Functional Programming Language Concepts 3 Introduction to FP 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

TIVDM2Functional Programming Language Concepts 4 Principles of FP Treats computation as evaluation of mathematical functions (and avoids state) Data and programs are represented in the same way Functions as first-class values – Higher-order functions: functions that operate on, or create, other functions – Functions as components of data structures Lambda calculus provides a theoretical framework for describing functions and their evaluation It is a mathematical abstraction rather than an imperative programming language

TIVDM2Functional Programming Language Concepts 5 History lambda calculus (Church, 1932) simply typed lambda calculus (Church, 1940) lambda calculus as prog. lang. (McCarthy(?), 1960, Landin 1965) polymorphic types (Girard, Reynolds, early 70s) algebraic types ( Burstall & Landin, 1969) type inference (Hindley, 1969, Milner, mid 70s) lazy evaluation (Wadsworth, early 70s) Equational definitions Miranda 80s Type classes Haskell 1990s Microsoft F# etc 2000s

TIVDM2Functional Programming Language Concepts 6 Varieties of FP languages Typed (ML, Haskell) vs untyped (Scheme, Erlang) Pure vs Impure impure have state and imperative features pure have no side effects, “referential transparency” Strict vs Lazy evaluation

TIVDM2Functional Programming Language Concepts 7 Declarative style of programming Declarative Style of programming - emphasis is placed on describing what a program should do rather than prescribing how it should do it. Functional programming - good illustration of the declarative style of programming. A program is viewed as a function from input to output. Logic programming – another paradigm A program is viewed as a collection of logical rules and facts (a knowledge-based system). Using logical reasoning, the computer system can derive new facts from existing ones.

TIVDM2Functional Programming Language Concepts 8 Functional style of programming A computing system is viewed as a function which takes input and delivers output. The function transforms the input into output. Functions are the basic building blocks from which programs are constructed. The definition of each function specifies what the function does. It describes the relationship between the input and the output of the function.

TIVDM2Functional Programming Language Concepts 9 Agenda Introduction to the Functional Programming Paradigm  The notion of higher order functions Polymorphic examples of standard higher order functions

TIVDM2Functional Programming Language Concepts 10 First-Class Functions Data values are first-class if they can be assigned to local variables be components of data structures be passed as arguments to functions be returned from functions be created at run-time

TIVDM2Functional Programming Language Concepts 11 Higher-order Functions Every function has an order: A function that does not take any functions as parameters, and does not return a function value, has order 1 A function that takes a function as a parameter or returns a function value has order n+1, where n is the order of its highest-order parameter or returned value A small example: Twice: (int -> int) * int -> int Twice(f,x) == f( f (x)) Or TwiceCur: (int -> int)-> int -> int TwiceCur(f)(x) == f( f (x))

TIVDM2Functional Programming Language Concepts 12 Functions in Programming Languages How functions are treated by programming languages? Languagepassed as arguments returned from functions nested scope JavaNo CYes No C++Yes No PascalYesNoYes Modula-3YesNoYes SchemeYes MLYes

TIVDM2Functional Programming Language Concepts 13 Nested Functions and Closures Return a function from function call function f(x) { var y = x; return function (z){y += z; return y;} } var h = f(5); h(3); In order to handle this one needs to introduce closures A closure is a function that captures the bindings of free variables in its lexical context.

TIVDM2Functional Programming Language Concepts 14 Agenda Introduction to the Functional Programming Paradigm The notion of higher order functions  Polymorphic examples of standard higher order functions

TIVDM2Functional Programming Language Concepts 15 Predefined Higher-Order Functions in Functional Languages We will use three important predefined higher-order functions: map filter foldr foldl Actually, foldr and foldl are very similar, as you might guess from the names

TIVDM2Functional Programming Language Concepts 16 The Map Function Map applies a function to every element of a list: -> seq -> seq Map(f)(list) == [f(list(i)) | i in set inds list]

TIVDM2Functional Programming Language Concepts 17 The Filter Function Filter selects every element that satisfies a predicate: -> bool) -> seq -> seq Filter(pred)(list) == [list(i) | i in set inds list & pred(list(i))]

TIVDM2Functional Programming Language Concepts 18 The FoldR Function Folds all elements in a list from the right into one value (a simple pattern of recursion): -> seq FoldR(f)(neutral)(list) == if list = [] then neutral else f(hd list,FoldR(f)(neutral)(tl list)) Example usage: Sum = FoldR(+)(0) Product = FoldR(*)(1) Or = FoldR(or)(false) And = FoldR(and)(true)

TIVDM2Functional Programming Language Concepts 19 Summary What have I presented today? Introduction to the Functional Programming Paradigm The notion of higher order functions Polymorphic examples of standard higher order functions What do you need to do now? Complete your distributed real time model for your project

TIVDM2Functional Programming Language Concepts 20 Quote of the day Program designers have a tendency to think of the users as idiots who need to be controlled. They should rather think of their program as a servant, whose master, the user, should be able to control it. If designers and programmers think about the apparent mental qualities that their programs will have, they'll create programs that are easier and pleasanter — more humane — to deal with. John McCarthy