Top Banner
Functional and Concurrent Programming Simon Thompson [email protected] CO545 Lecture 1
64

Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Mar 11, 2018

Download

Documents

phungkien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Functional and Concurrent Programming

Simon [email protected]

CO545 Lecture 1

Page 2: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

CO545: functional and concurrent programming

Page 3: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

CO545: functional and concurrent programming

Lectures22 lectures: introduction, functional programming,concurrent programming,

going further

Page 4: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

CO545: functional and concurrent programming

Classes10 seminars:

from next week.11 terminal sessions:

from this week

Lectures22 lectures: introduction, functional programming,concurrent programming,

going further

Page 5: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

CO545: functional and concurrent programming

Classes10 seminars:

from next week.11 terminal sessions:

from this week

Lectures22 lectures: introduction, functional programming,concurrent programming,

going further

LecturersSimon Thompson

[email protected] Dominic Orchard [email protected]

Page 6: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

CO545: functional and concurrent programming

Classes10 seminars:

from next week.11 terminal sessions:

from this week

ResourcesMoodle for

slides, lecture recordings, programs, class and seminar resources

Lectures22 lectures: introduction, functional programming,concurrent programming,

going further

LecturersSimon Thompson

[email protected] Dominic Orchard [email protected]

Page 7: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

What will I learn?

Page 8: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

What will I learn?

Functional ideasValues, names, evaluation,

structured types, lists, higher-order functions,

recursion, PBT.

Page 9: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

What will I learn?

Concurrent ideasProcesses and messages,process ids and spawn,

asynchrony and mailboxes,fail-safe and exits, …

Functional ideasValues, names, evaluation,

structured types, lists, higher-order functions,

recursion, PBT.

Page 10: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

What will I learn?

Concurrent ideasProcesses and messages,process ids and spawn,

asynchrony and mailboxes,fail-safe and exits, …

Functional ideasValues, names, evaluation,

structured types, lists, higher-order functions,

recursion, PBT.

Put it into practiceUsing these ideas in practice in the Erlang

programminglanguage.

Page 11: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

What will I learn?

Concurrent ideasProcesses and messages,process ids and spawn,

asynchrony and mailboxes,fail-safe and exits, …

ContextHaskell for “lazy”, typed

programming.Other concurrency models; scaling up Erlang systems.

Functional ideasValues, names, evaluation,

structured types, lists, higher-order functions,

recursion, PBT.

Put it into practiceUsing these ideas in practice in the Erlang

programminglanguage.

Page 12: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

How will I learn?

Page 13: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Four assessments: two functional, two concurrent.

How will I be assessed?

Page 14: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Four assessments: two functional, two concurrent.

Four assessments: two in-class, two take-home.

How will I be assessed?

Page 15: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Programming means making this …

Page 16: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Programming

http://www.cpu-world.com/forum/viewtopic.php?t=19888

Page 17: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Programming

Intel Xeon Phi 'Knight's Corner': 1+ teraFLOPS with double precision; 62 x86 processor cores and a 512 bit GDDR5 memory controller

Page 18: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

… do this

Page 19: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD
Page 20: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

… do this

Page 21: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

… do this

Page 22: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

A# .NET, A# (Axiom), A-0 System, A+, A++, ABAP, ABC, ABC ALGOL, ABLE, ABSET, ABSYS, ACC, Accent, Ace DASL, ACL2, ACT-III, Action!, ActionScript, Ada, Adenine, Agda, Agilent VEE, Agora, AIMMS, , ALF, ALGOL 58, ALGOL 60, ALGOL 68, ALGOL W, Alice, Alma-0, AmbientTalk, Amiga E, AMOS, AMPL, APL, App Inventor for Android's visual block language, AppleScript, Arc, ARexx, Argus, AspectJ, Assembly language, ATS, Ateji PX, AutoHotkey, Autocoder, AutoIt, AutoLISP / Visual LISP, Averest, AWK, Axum, B, Babbage, Bash, BASIC, bc, BCPL, BeanShell, Batch (Windows/Dos), Bertrand, BETA, Bigwig, Bistro, BitC, BLISS, Blue, Bon, Boo, Boomerang, Bourne shell, bash, ksh, BREW, BPEL, C, C--, C++, C#, C/AL, Caché ObjectScript, C Shell, Caml, Candle, Cayenne, CDuce, Cecil, Cel, Cesil, Ceylon, CFEngine, CFML, Cg, Ch, Chapel, CHAIN, Charity, Charm, Chef, CHILL, CHIP-8, chomski, ChucK, CICS, Cilk, CL, Claire, Clarion, Clean, Clipper, CLIST, Clojure, CLU, CMS-2, COBOL, Cobra, CODE, CoffeeScript, Cola, ColdC, ColdFusion, COMAL, Combined Programming Language, COMIT, Common Intermediate Language, Common Lisp, COMPASS, Component Pascal, Constraint Handling Rules, Converge, Cool, Coq, Coral 66, Corn, CorVision, COWSEL, CPL, csh, CSP, Csound, CUDA, Curl, Curry, Cyclone, Cython, D, DASL, DASL, Dart, DataFlex, Datalog, DATATRIEVE, dBase, dc, DCL, Deesel, Delphi, DCL, DinkC, DIBOL, Dog, Draco, DRAKON, Dylan, DYNAMO, E, E#, Ease, Easy PL/I, Easy Programming Language, EASYTRIEVE PLUS, ECMAScript, Edinburgh IMP, EGL, Eiffel, ELAN, Elixir, Elm, Emacs Lisp, Emerald, Epigram, EPL, Erlang, es, Escapade, Escher, ESPOL, Esterel, Etoys, Euclid, Euler, Euphoria, EusLisp Robot Programming Language, CMS EXEC, EXEC 2, Executable UML, F, F#, Factor, Falcon, Fancy, Fantom, FAUST, Felix, Ferite, FFP, Fjölnir, FL, Flavors, Flex, FLOW-MATIC, FOCAL, FOCUS, FOIL, FORMAC, @Formula, Forth, Fortran, Fortress, FoxBase, FoxPro, FP, FPr, Franz Lisp, F-Script, FSProg, G, Google Apps Script, Game Maker Language, GameMonkey Script, GAMS, GAP, G-code, Genie, GDL, Gibiane, GJ, GEORGE, GLSL, GNU E, GM, Go, Go!, Gödel, Godiva, GOM (Good Old Mad), Goo, Gosu, GOTRAN, GPSS, GraphTalk, GRASS, Groovy, Hack (programming language), HAL/S, Hamilton C shell, Harbour, Hartmann pipelines, Haskell, Haxe, High Level Assembly, HLSL, Hop, Hope, Hugo, Hume, HyperTalk, IBM Basic assembly language, IBM HAScript, IBM Informix-4GL, IBM RPG, ICI, Icon, Id, IDL, Idris, IMP, Inform, Io, Ioke, IPL, IPTSCRAE, ISLISP, ISPF, ISWIM, J, J#, J++, JADE, Jako, JAL, Janus, JASS, Java, JavaScript, JCL, JEAN, Join Java, JOSS, Joule, JOVIAL, Joy, JScript, JScript .NET, JavaFX Script, Julia, Jython, K, Kaleidoscope, Karel, Karel++, KEE, Kixtart, KIF, Kojo, Kotlin, KRC, KRL, KUKA, KRYPTON, ksh, L, L# .NET, LabVIEW, Ladder, Lagoona, LANSA, Lasso, LaTeX, Lava, LC-3, Leda, Legoscript, LIL, LilyPond, Limbo, Limnor, LINC, Lingo, Linoleum, LIS, LISA, Lisaac, Lisp, Lite-C, Lithe, Little b, Logo, Logtalk, LPC, LSE, LSL, LiveCode, LiveScript, Lua, Lucid, Lustre, LYaPAS, Lynx, M2001, M4, Machine code, MAD, MAD/I, Magik, Magma, make, Maple, MAPPER, MARK-IV, Mary, MASM Microsoft Assembly x86, Mathematica, MATLAB, Maxima, Macsyma, Max, MaxScript, Maya (MEL), MDL, Mercury, Mesa, Metacard, Metafont, MetaL, Microcode, MicroScript, MIIS, MillScript, MIMIC, Mirah, Miranda, MIVA Script, ML, Moby, Model 204, Modelica, Modula, Modula-2, Modula-3, Mohol, MOO, Mortran, Mouse, MPD, CIL, MSL, MUMPS, NASM, NATURAL, Napier88, Neko, Nemerle, nesC, NESL, Net.Data, NetLogo, NetRexx, NewLISP, NEWP, Newspeak, NewtonScript, NGL, Nial, Nice, Nickle, NPL, Not eXactly C, Not Quite C, NSIS, Nu, NWScript, NXT-G, o:XML, Oak, Oberon, Obix, OBJ2, Object Lisp, ObjectLOGO, Object REXX, Object Pascal, Objective-C, Objective-J, Obliq, Obol, OCaml, occam, occam-π, Octave, OmniMark, Onyx, Opa, Opal, OpenCL, OpenEdge ABL, OPL, OPS5, OptimJ, Orc, ORCA/Modula-2, Oriel, Orwell, Oxygene, Oz, P#, ParaSail (programming language), PARI/GP, Pascal, Pawn, PCASTL, PCF, PEARL, PeopleCode, Perl, PDL, PHP, Phrogram, Pico, Picolisp, Pict, Pike, PIKT, PILOT, Pipelines, Pizza, PL-11, PL/0, PL/B, PL/C, PL/I, PL/M, PL/P, PL/SQL, PL360, PLANC, Plankalkül, Planner, PLEX, PLEXIL, Plus, POP-11, PostScript, PortablE, Powerhouse, PowerBuilder, PowerShell, PPL, Processing, Processing.js, Prograph, PROIV, Prolog, PROMAL, Promela, PROSE modeling language, PROTEL, ProvideX, Pro*C, Pure, Python, Q (equational programming language), Q (programming language from Kx Systems), Qalb, Qi, QtScript, QuakeC, QPL, R, R++, Racket, RAPID, Rapira, Ratfiv, Ratfor, rc, REBOL, Red, Redcode, REFAL, Reia, Revolution, rex, REXX, Rlab, RobotC, ROOP, RPG, RPL, RSL, RTL/2, Ruby, RuneScript, Rust, S, S2, S3, S-Lang, S-PLUS, SA-C, SabreTalk, SAIL, SALSA, SAM76, SAS, SASL, Sather, Sawzall, SBL, Scala, Scheme, Scilab, Scratch, Script.NET, Sed, Seed7, Self, SenseTalk, SequenceL, SETL, Shift Script, SIMPOL, Shakespeare, SIGNAL, SiMPLE, SIMSCRIPT, Simula, Simulink, SISAL, SLIP, SMALL, Smalltalk, Small Basic, SML, Snap!, SNOBOL, SPITBOL, Snowball, SOL, Span, SPARK, SPIN, SP/k, SPS, Squeak, Squirrel, SR, S/SL, Stackless Python, Starlogo, Strand, Stata, Stateflow, Subtext, SuperCollider, SuperTalk, Swift (Apple programming language), Swift (parallel scripting language), SYMPL, SyncCharts, SystemVerilog, T, TACL, TACPOL, TADS, TAL, Tcl, Tea, TECO, TELCOMP, TeX, TEX, TIE, Timber, TMG, Tom, TOM, Topspeed, TPU, Trac, TTM, T-SQL, TTCN, Turing, TUTOR, TXL, TypeScript, Turbo C++, Ubercode, UCSD Pascal, Umple, Unicon, Uniface, UNITY, Unix shell, UnrealScript, Vala, VBA, VBScript, Verilog, VHDL, Visual Basic, Visual Basic .NET, Visual DataFlex, Visual DialogScript, Visual Fortran, Visual FoxPro, Visual J++, Visual J#, Visual Objects, Visual Prolog, VSXu, Vvvv, WATFIV, WATFOR, WebDNA, WebQL, Windows PowerShell, Winbatch, Wolfram, Wyvern, X++, X#, X10, XBL, XC, XMOS architecture, xHarbour, XL, Xojo, XOTcl, XPL, XPL0, XQuery, XSB, XSLT, XPath, Xtend, Yorick, YQL, Z notation, Zeno, ZOPL, ZPL.

A list of programming languages fetched from Wikipedia in CSV format – https://github.com/jamhall/programming-languages-csv

Page 23: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Hardware

Low-level but …

… fiendishly complicated.

Page 24: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

The Turing machine

http://www.math.uri.edu/~kulenm/mth381pr/comput/fig.jpg

Page 25: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

The von Neumann model

By Kapooht - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=25789639

Page 26: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Computation is …

… performed in a sequence of steps

… through changing values stored in memory

The von Neumann model

Page 27: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Scaling up the von Neumann model

assembler

machine code

Page 28: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Scaling up the von Neumann model

assembler

machine code

Page 29: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Instructions to store and fetch values from memory …

… and to perform arithmetical operations on these values and registers.

Linear sequence of code, with (un)conditional jumps.

Page 30: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Instructions to store and fetch values from memory …

… and to perform arithmetical operations on these values and registers.

Linear sequence of code, with (un)conditional jumps.

Plus symbolic names, library routines.

Page 31: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Symbolic variables, simple control structures …

… reuse of sections of code, using global variables.

Page 32: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Symbolic variables, simple control structures …

… reuse of sections of code, w/parameters, return values, scopes.

Defined composite data types.

Page 33: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Group together variables with the procedures and functions that operate on them.

Page 34: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Levels of abstraction

assembler

machine code

Group together variables with the procedures and functions that operate on them.

Inheritance allows objects to extend / modify other objects.

Page 35: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

Page 36: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code 010010…

Page 37: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

SPARC, 86x, …

010010…

Page 38: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

BASIC

SPARC, 86x, …

010010…

Page 39: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

Pascal, Modula 2

BASIC

SPARC, 86x, …

010010…

Page 40: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

JavaScript, Haxe

Pascal, Modula 2

BASIC

SPARC, 86x, …

010010…

Page 41: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

object-oriented

object-based

structured

procedural

Examples

assembler

machine code

Java, C#, C++

JavaScript, Haxe

Pascal, Modula 2

BASIC

SPARC, 86x, …

010010…

Page 42: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

The von Neumann model

By Kapooht - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=25789639

Page 43: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Calculation

http://www.wikihow.com/Evaluate-an-Algebraic-Expression

Page 44: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Calculation

Computation = calculation.

Programming = defining your own functions

f x y = 4*x + 3*y

? f 2 6 ——> 4*2 + 3*6 ——> 8 + 18 ——> 26

Page 45: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Calculation

No variables / storage locations.

Just values of expressions … … and names for values.

f x y = 4*x + 3*y

? f 2 6 ——> 4*2 + 3*6 ——> 8 + 18 ——> 26

Page 46: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Abstraction hiding the VNM

No variables / storage locations.

Just values of expressions … … and names for values.

Page 47: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Abstraction hiding the VNM

No variables / storage locations.

Just values of expressions … … and names for values. Von Neumann

Storage allocation, modification, data structure mutation

Page 48: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Abstraction hiding the VNM

No variables / storage locations.

Just values of expressions … … and names for values.

CalculationImmutable data

Named values and subexpressions

Von NeumannStorage allocation, modification, data structure mutation

Page 49: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

The variety of functional languages

LISPEarliest language with funs.Symbolic computing: eval.

Weak types.AI applications

ErlangWeakly typed, strict.

Concurrency at heart.Side effects controlled.

Use? telecoms, WhatsApp, …

HaskellLeading “lazy” language: calculate on demand.

Strongly typed. Side effects only via “monads”

OCamlStrongly typed but “strict”.Side effects but controlled.

Systems programming e.g XenBasis of F# (in .NET fwd)

Page 50: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

The variety of functional languages

LISPEarliest language with funs.Symbolic computing: eval.

Weak types.AI applications

ErlangWeakly typed, strict.

Concurrency at heart.Side effects controlled.

Use? telecoms, WhatsApp, …

HaskellLeading “lazy” language: calculate on demand.

Strongly typed. Side effects only via “monads”

OCamlStrongly typed but “strict”.Side effects but controlled.

Systems programming e.g XenBasis of F# (in .NET fwd)

Page 51: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Interpreter

programsource

resultsprogram

Page 52: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

programsource

programtarget

Page 53: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

front endprogram

sourceprogramtargetback

end IR

Page 54: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

front endprogram

sourceprogramtargetback

end IRoptimiser

IR

Page 55: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

front endprogram

sourceprogramtargetback

end IRoptimiser

IR

Uncover the structure in the text

Lexical analysis: find the words.Parsing: find the structure.Analysis: find aspects of the meaning.Generate an intermediate representation.

Page 56: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

front endprogram

sourceprogramtargetback

end IRoptimiser

IR

Uncover the structure in the text

Lexical analysis: find the words.Parsing: find the structure.Analysis: find aspects of the meaning.Generate an intermediate representation.

IR: e.g. SSA formatOptimisation = Analysis + Transformation Optimiser will combine many small optimisations e.g … … data flow: float out calculations from loops.

Page 57: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Compiler

front endprogram

sourceprogramtargetback

end IRoptimiser

IR

Uncover the structure in the text

Lexical analysis: find the words.Parsing: find the structure.Analysis: find aspects of the meaning.Generate an intermediate representation.

Generate instructions for the target machine.Allocating registers to symbolic variables.Scheduling instructions.

IR: e.g. SSA formatOptimisation = Analysis + Transformation Optimiser will combine many small optimisations e.g … … data flow: float out calculations from loops.

Page 58: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Concurrency

+

Page 59: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Concurrency

+

Page 60: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Concurrency

+Threads = multiple modifiers + one memory

Page 61: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Concurrency

+Threads = multiple modifiers + one memory

Processes = multiple modifiers + their own memory

Page 62: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Fight over scarce resources

http://www.dailymail.co.uk/news/article-2852585/Mayhem-Black-Friday-begins-Shoppers-clash-supermarkets-trying-grab-bargains-Boots-Game-Curry-s-PC-world-websites-crash-thousands-start-hunt-Christmas-deals.html

Page 63: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Message-passing concurrency

Each process has its own memory …

… garbage collected separately, too.

Communication is via message passing …

… no shared memory at all.

Concurrency is a design artefact …

… but maps onto hardware parallelism.

Page 64: Functional and Concurrent Programming - University of · PDF fileFunctional and Concurrent Programming Simon Thompson ... programs, class and seminar ... Turbo C++, Ubercode, UCSD

Don’t forget …

Lecture tomorrow 10:00 in Woolf Lecture Theatre …

… and terminal sessions start this week.