06/01/101 Functional Programming GC16 / 3011 Chris Clack.

Slides:



Advertisements
Similar presentations
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Gerardo Schneider Department of Informatics University of Oslo December 2008.
Overview of Programming Paradigms
Chapter 15 Other Functional Languages. Copyright © 2007 Addison-Wesley. All rights reserved. Functional Languages Scheme and LISP have a simple syntax.
CS 101 Course Summary December 5, Big Ideas Abstraction Problem solving Fundamentals of programming.
A Quick Overview of Languages. FORTRAN Designed in 1955 First release of the compiler in 1957 Algebraic in nature Scientific (numeric not string oriented)
COMP205 Comparative Programming Languages
Comp 205: Comparative Programming Languages Imperative Programming Languages Functional Programming Languages Semantics Other Paradigms Lecture notes,
Introduction to Programming Programming. COMP102 Prog. Fundamentals I: Introduction / Slide 2 Objectives l To learn fundamental problem solving techniques.
Introduction to Programming. COMP104 Introduction / Slide 2 Objectives * To learn fundamental problem solving techniques * To learn how to design a program.
Introduction to Programming (in C++) Introduction Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Announcements — Tues., Jan. 19 For next time, read Learning Computing with Robots, chs. 1 and 2. The Blackboard site is up and operational! not much content.
The Variety of Programming Languages D Goforth COSC 3127 D Goforth COSC 3127.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
Programming languages1 Programming paradigms Families of programming languages.
©Xiaoying Gao, Peter Andreae First Java Program COMP 102 #2 2014T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Object-Oriented Programming and Problem Solving Dr. Ramzi Saifan.
First Java Program COMP 102 #2 2015T2 Xiaoying Sharon Gao Computer Science Victoria University of Wellington.
Programming History. Who was the first programmer?
1 Programming Language History and Evolution In Text: Chapter 2.
CS3518 Languages and Computability Kees van Deemter Lectures Monday14:00New King’s 14 Tuesday11:00KC T2 Tutorials/Practicals Tuesday13:00-15:00.
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
CS 345: Programming Language Paradigms Chris Brooks HR 510 MWF 11:00-12:05.
Statement Level Flow of Control Iteration Structures Copyright © by Curt Hill.
Introduction Copyright © Software Carpentry This work is licensed under the Creative Commons Attribution License See
Analysis of Programming Languages (2). 2 LANGUAGE DESIGN CONSTRAINTS  Computer architecture  Technical setting  Standards  Legacy systems.
Programming Languages
int k = Integer.MAX_VALUE; k++; int k = Integer.MAX_VALUE; k++; What happens when the following code executes? byte b = someFile.readByte(); b = (byte)(b.
CPS120: Introduction to Computer Science Variables and Constants.
Textbook C for Scientists and Engineers © Prentice Hall 1997 Available at NUS CO-OP at S$35.10.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
CS 603: Programming Language Organization Lecture 1 Spring 2003 Department of Computer Science University of Alabama Joel Jones.
CS 2303 Systems Programming Concepts Bob Kinicki A08.
서울대한양대 ( 안 산 ) 충남대 1년1년 컴퓨터기초 (C) 컴퓨터프로그래밍 (C, Java) 컴퓨터프로그래밍 (C) 2. 봄 프로그래밍 원리 (Scheme, ML) Structure & Interpretation of Computer Programs 프로그래밍 방법론.
Software Engineering Algorithms, Compilers, & Lifecycle.
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Programming Language Paradigms ITSK2314 Lecture 3.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
History. Development Driven by Function Functions of a Programming Language –To describe computation for use by computers –To describe computation and.
CPS120 Introduction to Computer Science High Level Language: Paradigms.
Functional Programming Lecture 1 - Introduction Professor Muffy Calder.
Programming Language History and Evolution
Programming Languages and Data Organization
Chapter 5: Preparing C Programs
Basic Concepts: computer, program, programming …
What is a Functional Language?
Introduction to programming languages, Algorithms & flowcharts
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.
Basic 1964 PC general purpose Imperative Small Easy to use.
Introduction to programming languages, Algorithms & flowcharts
Problem Solving Using C: Orientation & Lecture 1
Comp 205: Comparative Programming Languages
Programming Language History and Evolution
Introduction to programming languages, Algorithms & flowcharts
Programming Language Design
صياغة البرامج ولغات البرمجة Programming & programming languages
Scope.
Overview of Programming Paradigms
Programming Languages and Paradigms
Abstract data types Programming Language Design and Implementation
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Programming Paradigms and Languages
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

06/01/101 Functional Programming GC16 / 3011 Chris Clack

06/01/102 Functional Programming This Lecture:This Lecture: IntroductionIntroduction Simple exampleSimple example Haiku or Karate? (industrial example)Haiku or Karate? (industrial example) The CourseThe Course

06/01/103 How many programming languages do you think exist?How many programming languages do you think exist? Java, C++, Cobol, Fortran, Basic, APL, C, Pascal, Haskell, Miranda, Prolog, LISP…Java, C++, Cobol, Fortran, Basic, APL, C, Pascal, Haskell, Miranda, Prolog, LISP… How many languages can you use? How many languages can you use? Are all these other languages just “junk”? Are all these other languages just “junk”? Why can’t you use Java for everything? Why can’t you use Java for everything? Introduction

06/01/104 What’s COOL about HOT languages?What’s COOL about HOT languages? What’s NEAT about GARBAGE?What’s NEAT about GARBAGE? How can a LAZY language improve performance?How can a LAZY language improve performance? Some languages support “infinite” data structures …(…how do they do that?)Some languages support “infinite” data structures …(…how do they do that?) Introduction

06/01/105 ImperativeImperative versus Declarative FunctionalFunctional versus Logic “instructing“instructing a machine” versus “solving a problem” Java C++ FORTRAN LISP Prolog SML Miranda Haskell Introduction

06/01/106 Assume “results” is the name of a variable that contains a sequence of 100 integers;Assume “results” is the name of a variable that contains a sequence of 100 integers; write code to select all those less than 10write code to select all those less than 10 Simple Example

06/01/107 int small[100]; for (j=0,k=0; j<100; j++){ if (results[j]<10) { small[k]=results[j]; k++; } } return(small); Simple Example - imperative

06/01/108 filter (< 10) results Simple Example - functional

06/01/109 FP languages are renowned for their eleganceFP languages are renowned for their elegance But - are they like Japanese “Haiku” poetry?But - are they like Japanese “Haiku” poetry? (elegant but not very practical)(elegant but not very practical) Or - are they like Karate?Or - are they like Karate? (elegant and useful in a fight)(elegant and useful in a fight) Haiku or Karate?

06/01/1010 Prototyping O-O Designs Using FP Techniques Haiku or Karate?

06/01/1011 Haiku or Karate? – the problem Commercial ConstraintsCommercial Constraints The world’s largest IT ConsultancyThe world’s largest IT Consultancy An international Settlement BankAn international Settlement Bank A “mission-critical” financial systemA “mission-critical” financial system Over 100 programmersOver 100 programmers C++ required by clientC++ required by client

06/01/1012 Haiku or Karate? – the problem The System:The System: A network of components

06/01/1013 Haiku or Karate? – the problem Requirements:Requirements: –Discrete-event simulation of component network –Prototyping of central (optimisation and approximation) algorithms

06/01/1014 The main problem is C++

06/01/1015 Haiku or Karate? – constraints C++ “not viable” for prototyping/simulationC++ “not viable” for prototyping/simulation take too long to develop underlying componentstake too long to develop underlying components rapid-prototyping O-O language (e.g. Smalltalk) “not desirable”rapid-prototyping O-O language (e.g. Smalltalk) “not desirable” raises question about overall suitability of C++raises question about overall suitability of C++ Alternative approach: use a Functional Language (“Miranda”) HOT, LAZY, with GARBAGE COLLECTIONHOT, LAZY, with GARBAGE COLLECTION NO POINTERS. NO ASSIGNMENTNO POINTERS. NO ASSIGNMENT

06/01/1016 Haiku or Karate? – selling points Speed and Clarity with which algorithms can be:Speed and Clarity with which algorithms can be: expressedexpressed validatedvalidated Can simulate key O-O designs in detailCan simulate key O-O designs in detail with minimal detail for other componentswith minimal detail for other components Access to expertise:Access to expertise: a “champion”a “champion”

06/01/1017 Haiku or Karate? – selling points Note: Speed of execution was almost totally irrelevant!Note: Speed of execution was almost totally irrelevant!

06/01/1018 Haiku or Karate? - techniques Modelling the component networkModelling the component network ab cd c1c2 c3 c4 c5 c6 c7 c8 c9 file1 file2

06/01/1019 Haiku or Karate? - techniques c1 = read “file1” c5 = read “file2” c9 = b (c2, c6, c8) (c2, c3) = a (c1, c4) (c4, c6) = c (c5, c7) (c7, c8) = d c3 Recursive (looping) functions a, b, c and d c1, c2 etc. are potentially-infinite streams of (time, value) events

06/01/1020 Haiku or Karate? - techniques Simulating behaviourSimulating behaviour simple behavioural executable specificationsimple behavioural executable specification expression-basedexpression-based synthetic (statistical) data generationsynthetic (statistical) data generation Could also use Miranda algorithms as specification for subsequent implementation in C++

06/01/1021 Haiku or Karate? - results Rapid DevelopmentRapid Development Concise Expression Simulation and specification of complex processes »About five times faster than C++ »6 pages of Miranda = about 25 pages of C++ »design optimised early in lifecycle »confidence increased through validation on real data

06/01/1022 Haiku or Karate? - results Almost NO errors in prototype codeAlmost NO errors in prototype code Vast reduction in errors in final C++ codeVast reduction in errors in final C++ code Viewed as a commercial advantageViewed as a commercial advantage Promoted within Andersen Consulting - part of “Method/1”Promoted within Andersen Consulting - part of “Method/1” “champion” now promoted to Manager“champion” now promoted to Manager

06/01/1023 Focus:Focus: Fab FeaturesFab Features Ingenious ImplementationIngenious Implementation Programming SkillsProgramming Skills Add another language/paradigm to your CVAdd another language/paradigm to your CV Vehicle:Vehicle: A functional language “Miranda”A functional language “Miranda” Elegant implementation technologyElegant implementation technology Extends to other languages (e.g. Java)Extends to other languages (e.g. Java) Coursework: 10% ( 1 coursework, may be MCT )Coursework: 10% ( 1 coursework, may be MCT ) The Course

06/01/1024 LECTURES:LECTURES: Monday 12-1pm25 Gordon Square 107Monday 12-1pm25 Gordon Square 107 Tuesday 9-10amMPEB 1.02Tuesday 9-10amMPEB 1.02 Friday 11-12noonRoberts 110Friday 11-12noonRoberts 110 PRACTICALS (TBA: if/when I have a demonstrator!):PRACTICALS (TBA: if/when I have a demonstrator!): Friday 4-5pmMPEB 1.21Friday 4-5pmMPEB 1.21 Tuesday 9-10amDOUBLE BOOKEDTuesday 9-10amDOUBLE BOOKED mostly for GC16, less relevant for 3011mostly for GC16, less relevant for 3011 Demonstrator – TBADemonstrator – TBA The Course - Lectures

06/01/1025 “Lambda Calculus” - a simple introduction“Lambda Calculus” - a simple introduction Introduction to MirandaIntroduction to Miranda developing some programming skillsdeveloping some programming skills developing problem-solving (thinking) skillsdeveloping problem-solving (thinking) skills Introduction to implementation techniquesIntroduction to implementation techniques graph reductiongraph reduction memory management (cf. C, C++, algorithms)memory management (cf. C, C++, algorithms) garbage collection (cf. Java)garbage collection (cf. Java) The Course - Topics

06/01/1026 Programming with Miranda, Clack, Myers and Poon, Prentice-Hall 1994 ISBN X.Programming with Miranda, Clack, Myers and Poon, Prentice-Hall 1994 ISBN X. Research Directions in Parallel Functional Programming, Hammond and Michaelson (Eds.), Springer, ISBN , 1999Research Directions in Parallel Functional Programming, Hammond and Michaelson (Eds.), Springer, ISBN , 1999 The Implementation of Functional Programming Languages, Peyton-Jones, Prentice-Hall 1986The Implementation of Functional Programming Languages, Peyton-Jones, Prentice-Hall 1986 Garbage Collection: Algorithms for Automatic Dynamic Memory Management, Jones and Lins, Wiley 1996 ISBN Garbage Collection: Algorithms for Automatic Dynamic Memory Management, Jones and Lins, Wiley 1996 ISBN The Course - Books

06/01/ The Course - Communication