Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "06/01/101 Functional Programming GC16 / 3011 Chris Clack."— Presentation transcript:

1

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

3 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

4 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

5 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

6 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

7 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

8 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

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

10 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?

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

12 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

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

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

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

16 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

17 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”

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

19 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

20 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

21 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++

22 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

23 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

24 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

25 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

26 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

27 06/01/1026 Programming with Miranda, Clack, Myers and Poon, Prentice-Hall 1994 ISBN 0-13-192592-X.Programming with Miranda, Clack, Myers and Poon, Prentice-Hall 1994 ISBN 0-13-192592-X. Research Directions in Parallel Functional Programming, Hammond and Michaelson (Eds.), Springer, ISBN 1-85233- 092-9, 1999Research Directions in Parallel Functional Programming, Hammond and Michaelson (Eds.), Springer, ISBN 1-85233- 092-9, 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 0 471 94148 4Garbage Collection: Algorithms for Automatic Dynamic Memory Management, Jones and Lins, Wiley 1996 ISBN 0 471 94148 4 The Course - Books

28 06/01/1027 3011@cs.ucl.ac.uk (3011-request@cs.ucl.ac.uk)3011@cs.ucl.ac.uk (3011-request@cs.ucl.ac.uk)3011-request@cs.ucl.ac.uk gc16@cs.ucl.ac.uk (gc16-request@cs.ucl.ac.uk)gc16@cs.ucl.ac.uk (gc16-request@cs.ucl.ac.uk)16-request@cs.ucl.ac.uk http://www.cs.ucl.ac.uk/teaching/3c11http://www.cs.ucl.ac.uk/teaching/3c11 http://www.cs.ucl.ac.uk/teaching/D16http://www.cs.ucl.ac.uk/teaching/D16 The Course - Communication


Download ppt "06/01/101 Functional Programming GC16 / 3011 Chris Clack."

Similar presentations


Ads by Google