1 / 27

Chris Clack

Functional Programming GC16 / 3011. Chris Clack. Functional Programming. This Lecture: Introduction Simple example Haiku or Karate? (industrial example) The Course. Introduction. How many programming languages do you think exist?

cargan
Download Presentation

Chris Clack

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. Functional Programming GC16 / 3011 Chris Clack

  2. Functional Programming • This Lecture: • Introduction • Simple example • Haiku or Karate? (industrial example) • The Course

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

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

  5. Introduction SML Miranda Haskell • Imperative versus Declarative • Functional versus Logic • “instructing a machine” versus “solving a problem” Java C++ FORTRAN LISP Prolog

  6. Simple Example • Assume “results” is the name of a variable that contains a sequence of 100 integers; • write code to select all those less than 10

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

  8. Simple Example - functional filter (< 10) results

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

  10. Haiku or Karate? Prototyping O-O DesignsUsing FP Techniques

  11. Haiku or Karate? – the problem • Commercial Constraints • The world’s largest IT Consultancy • An international Settlement Bank • A “mission-critical” financial system • Over 100 programmers • C++ required by client

  12. Haiku or Karate? – the problem • The System: A network of components

  13. Haiku or Karate? – the problem • Requirements: • Discrete-event simulation of component network • Prototyping of central (optimisation and approximation) algorithms

  14. The main problem is C++

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

  16. Haiku or Karate? – selling points • Speed and Clarity with which algorithms can be: • expressed • validated • Can simulate key O-O designs in detail • with minimal detail for other components • Access to expertise: • a “champion”

  17. Haiku or Karate? – selling points • Note: Speed of execution was almost totally irrelevant!

  18. c1 c2 c9 a b c3 c4 c8 c6 c5 c d c7 Haiku or Karate? - techniques • Modelling the component network file1 file2

  19. 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

  20. Haiku or Karate? - techniques • Simulating behaviour • simple behavioural executable specification • expression-based • synthetic (statistical) data generation • Could also use Miranda algorithms as specification for subsequent implementation in C++

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

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

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

  24. The Course - Lectures • LECTURES: • Monday 12-1pm 25 Gordon Square 107 • Tuesday 9-10am MPEB 1.02 • Friday 11-12noon Roberts 110 • PRACTICALS (TBA: if/when I have a demonstrator!): • Friday 4-5pm MPEB 1.21 • Tuesday 9-10am DOUBLE BOOKED • mostly for GC16, less relevant for 3011 • Demonstrator – TBA

  25. The Course - Topics • “Lambda Calculus” - a simple introduction • Introduction to Miranda • developing some programming skills • developing problem-solving (thinking) skills • Introduction to implementation techniques • graph reduction • memory management (cf. C, C++, algorithms) • garbage collection (cf. Java)

  26. The Course - Books • 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, 1999 • The 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 4

  27. The Course - Communication • 3011@cs.ucl.ac.uk (3011-request@cs.ucl.ac.uk) • gc16@cs.ucl.ac.uk (gc16-request@cs.ucl.ac.uk) • http://www.cs.ucl.ac.uk/teaching/3c11 • http://www.cs.ucl.ac.uk/teaching/D16

More Related