Do Extraterrestrials Use Functional Programming?

Size: px
Start display at page:

Download "Do Extraterrestrials Use Functional Programming?"

Transcription

1 Do Extraterrestrials Use Functional Programming? Manuel M T Chakravarty University of New South Wales» Straight to next slide [15min Question (λ); 20min Methodology; 15min Application] mchakravarty α TacticalGrace TacticalGrace

2 This talk will be in three parts. (1) Discussing essence of functional programming. What makes FP tick? (2) How do FP principles influence software dev? Will propose a dev methodology for FP. (3) Look at concrete dev project, where we applied this methodology.»»let's start with The Question Part 1 The Question

3 » <Read question> * To visit us, they need to be on an advanced technological level with a deep understanding of science. * They won't speak one of humanity's languages, though. So, how do we establish a common basis? Do Extraterrestrials Use Functional Programming?

4 * How to communicate? * Common idea: universal principles may help establish a basis universal constants or universal laws.

5 * How to communicate? * Common idea: universal principles may help establish a basis universal constants or universal laws.

6 * How to communicate? * Common idea: universal principles may help establish a basis universal constants or universal laws. π?

7 E = mc 2 π? * How to communicate? * Common idea: universal principles may help establish a basis universal constants or universal laws.

8 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related

9 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alonzo Church

10 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alonzo Church

11 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alonzo Church

12 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alonzo Church

13 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alonzo Church

14 * Computer languages? Agree on a common language of computation? * In 1936, Alonzo Church introduced the lambda calculus: <Explain lambda calculus> * Serve as a common language? Like a computational Esperanto? * Also other calculi/machines. Famous: Turing machines. Which would aliens pick?»» Let's look: how are they related M, N x λx.m M N Alan Turing Alonzo Church

15 M, N x λx.m M N Alan Turing Alonzo Church * The lambda calculus and Turing machines have the same origin. * Beginning 20th century: group of famous mathematicians interested in formalising foundation of mathematics.»» This led to an important question

16 Lambda Calculus Turing Machine M, N x λx.m M N * The lambda calculus and Turing machines have the same origin. * Beginning 20th century: group of famous mathematicians interested in formalising foundation of mathematics.»» This led to an important question

17 Lambda Calculus Turing Machine M, N x λx.m M N By-product of a study of the foundation and expressive power of mathematics. * The lambda calculus and Turing machines have the same origin. * Beginning 20th century: group of famous mathematicians interested in formalising foundation of mathematics.»» This led to an important question

18 David Hilbert * Challenge posed by David Hilbert, 1928: the Entscheidungsproblem (decision problem) * Church & Turing, 1936, no solution, using lambda calculus & Turing machines.»» So what is the Entscheidungsproblem

19 Is there a solution to the David Hilbert Entscheidungsproblem? * Challenge posed by David Hilbert, 1928: the Entscheidungsproblem (decision problem) * Church & Turing, 1936, no solution, using lambda calculus & Turing machines.»» So what is the Entscheidungsproblem

20 Is there a solution to the David Hilbert Entscheidungsproblem? No! No! * Challenge posed by David Hilbert, 1928: the Entscheidungsproblem (decision problem) * Church & Turing, 1936, no solution, using lambda calculus & Turing machines.»» So what is the Entscheidungsproblem

21 Is there an algorithm to decide whether a given statement is provable from a set of axioms using the rules of first-order logic? * In other words: Given a world & a set of fixed rules in the world, check whether the world has a particular property.»» In turn, leads to the question

22 How do you prove that an algorithm does not exist? * Because we cannot solve the challenge, doesn't mean it is unsolvable? * Need systematic way to rigorously prove that a solution is impossible.»» Church & Turing proceeded as follows

23 * 1936, the concept of an algorithm remained to be formally defined

24 (1) Define a universal language or abstract machine. (2) Show that the desired algorithm cannot be expressed in the language. * 1936, the concept of an algorithm remained to be formally defined

25 Define a universal language or abstract machine. * Two steps <Explain> * Church & Turing used: (1) lambda term, (2) Turing machine * Hypothesis: universal ie, any algorithmically computable function can be expressed»» They showed

26 Define a universal language or abstract machine. Lambda Calculus Turing Machine M, N x λx.m M N * Two steps <Explain> * Church & Turing used: (1) lambda term, (2) Turing machine * Hypothesis: universal ie, any algorithmically computable function can be expressed»» They showed

27 Universal language Lambda Calculus Turing Machine M, N x λx.m M N * Two steps <Explain> * Church & Turing used: (1) lambda term, (2) Turing machine * Hypothesis: universal ie, any algorithmically computable function can be expressed»» They showed

28 Universal language Church-Turing thesis Lambda Calculus Turing Machine M, N x λx.m M N * Two steps <Explain> * Church & Turing used: (1) lambda term, (2) Turing machine * Hypothesis: universal ie, any algorithmically computable function can be expressed»» They showed

29 Computational Power Lambda Calculus Turing Machine M, N x λx.m M N = * Any program expressible in one is expressible in the other.»» However,

30 Generality Lambda Calculus Turing Machine M, N x λx.m M N * Lambda calculus: embodies concept of (functional) *abstraction* * Functional abstraction is only one embodiment of an underlying more general concept.»» This is important, as

31 Generality Lambda Calculus, N x λx.m M N Turing Machine * Lambda calculus: embodies concept of (functional) *abstraction* * Functional abstraction is only one embodiment of an underlying more general concept.»» This is important, as

32 Generality increases if a discovery is independently made in a variety of contexts.» Read the statement. * If a concept transcends one application, its generality increases.»» This is the case for the lambda calculus

33 Simply typed lambda calculus * Firstly, lambda calculus (no polytypes)»» Mathematicians Haskell Curry & William Howard discovered: it is structurally equivalent to

34 Lambda calculus with monotypes Simply typed lambda calculus * Firstly, lambda calculus (no polytypes)»» Mathematicians Haskell Curry & William Howard discovered: it is structurally equivalent to

35 Intuitionistic propositional logic»» Later, Joachim Lambek found: they correspond to

36 Constructive logic Intuitionistic propositional logic»» Later, Joachim Lambek found: they correspond to

37 Cartesian Simply Intuitionistic typed closed propositional lambda categories calculus logic * Three independently discovered artefacts share the same structure! * Implies an equivalence between programming & proving.»» The upshot of all this

38 Structure from category theory Cartesian Simply Intuitionistic typed closed propositional lambda categories calculus logic * Three independently discovered artefacts share the same structure! * Implies an equivalence between programming & proving.»» The upshot of all this

39 Simply typed lambda calculus Curry-Howard-Lambek correspondence Intuitionistic propositional logic Cartesian closed categories * Three independently discovered artefacts share the same structure! * Implies an equivalence between programming & proving.»» The upshot of all this

40 Alonzo Church didn't invent the lambda calulus; he discovered it.» Read the statement. * Just like Issac Newton didn't invent the Law of Gravity, but discovered it.»» Getting back to our extraterrestrials

41 * Lambda calculus: fundamental, inevitable, universal notion of computation. * In all likelihood: extraterrestials know about it, like they will know π.

42 * Lambda calculus: fundamental, inevitable, universal notion of computation. * In all likelihood: extraterrestials know about it, like they will know π.

43 M, N x λx.m M N M, N x λx.m M N * Lambda calculus: fundamental, inevitable, universal notion of computation. * In all likelihood: extraterrestials know about it, like they will know π.

44 * Is all this simply a academic curiosity? * Does it impact the practical use of FLs?»» It is crucial for FLs So what?

45 * FLs: pragmatic renderings of lambda calculus with syntactic sugar etc for convenience. * Important application: compilation via extended lambda calculi as ILs (eg, GHC)»» Moreover, central language features

46 Elm Racket Clojure Scheme SASL SISAL Scala Agda F# Clean OCaml Haskell J Standard ML Erlang Id LISP ISWIM λ Hope Miranda FP * FLs: pragmatic renderings of lambda calculus with syntactic sugar etc for convenience. * Important application: compilation via extended lambda calculi as ILs (eg, GHC)»» Moreover, central language features

47 Elm Racket Clojure Scheme SASL SISAL Scala Agda F# Clean OCaml Haskell J Standard ML Erlang Id LISP ISWIM λ Hope Miranda FP Central language features of FLs have their origin in the lambda calculus: * HO functions & closures: lambda * Purity & immutable structures: functional semantics * Types & semantics: logic & Curry-Howard

48 Elm Immutable Racket structures Agda Clojure Scala Scheme SASL SISAL Higher-order functions ISWIM & closures LISP F# Clean Purity OCaml Haskell Types J Standard ML Well-defined Erlang semantics Id λ Miranda Hope FP Central language features of FLs have their origin in the lambda calculus: * HO functions & closures: lambda * Purity & immutable structures: functional semantics * Types & semantics: logic & Curry-Howard

49 Immutable structures Purity Types Well-defined Higher-order semantics functions & closures * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

50 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

51 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

52 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Concurrency & parallelism Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

53 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Meta programming Concurrency & parallelism Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

54 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Meta programming Reuse Concurrency & parallelism Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

55 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Strong isolation Meta programming Reuse Concurrency & parallelism Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

56 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Strong isolation Meta programming Safety Reuse Concurrency & parallelism Practical advantages * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

57 Immutable structures Higher-order functions & closures Types Well-defined semantics Purity Language features Strong isolation Meta programming Safety Reuse Concurrency & parallelism Practical advantages Formal reasoning * Language features lead to practical advantages * Some examples: <explain where they come from>»» Nevertheless, we can gain even more from the foundation of FP than these advantages

58 Part 2 From Language to Methodology * Part 1: FP derives from natural, fundamental concept of computation... *...which is the root of language conveniences and practical advantages.»» We want to take that concept one step further

59 Functional programming as a development methodology, not just a language category.» We want to use <read the statement>. * Use the principles of the lambda calculus for a software development methodology. [Engineering is based on science. This is the science of programming/software.]»» To do this

60 The key to functional software development is a consistent focus on properties.» We need to realise that <read the statement> * These can be "logical properties" or "mathematical properties".»» More precisely,

61 Properties * Properties are rigorous and precise. (NB: PL is a formal notation.) * We are not talking about specifying the entire behaviour of an applications. (Type signatures are properties.) * In one way or another, they leverage the formal foundation of the lambda calculus.»» Let's look at some examples

62 * Properties are rigorous and precise. (NB: PL is a formal notation.) * We are not talking about specifying the entire behaviour of an applications. (Type signatures are properties.) * In one way or another, they leverage the formal foundation of the lambda calculus.»» Let's look at some examples Properties Rigorous, formal or semi-formal specification Cover one or more aspects of a program Leverage the mathematics of the lambda calculus

63 » Read the statement. * Menas: if you know the arguments, you know the result. * (1) Nothing else influences the result; (2) the function doesn't do anything, but provide the result. * This is semi-formal, but easy to formalise. A pure function is fully specified by a mapping of argument to result values.

64 » Read the statement. * Menas: if you know the arguments, you know the result. * (1) Nothing else influences the result; (2) the function doesn't do anything, but provide the result. * This is semi-formal, but easy to formalise. Well known property A pure function is fully specified by a mapping of argument to result values.

65 map :: (a -> b) -> [a] -> [b] eval :: Expr t -> t n+m m+n : {n m : N} -> m + n n + m * map: well known * eval: type-safe evaluator with GADTs * Agda lemma: commutativity of addition»» Types are not just for statically typed languages

66 Types are properties map :: (a -> b) -> [a] -> [b] eval :: Expr t -> t n+m m+n : {n m : N} -> m + n n + m * map: well known * eval: type-safe evaluator with GADTs * Agda lemma: commutativity of addition»» Types are not just for statically typed languages

67 Racket (Scheme dialect) * HTDP encourages the use of function signatures as part of the design process. * It also uses data definitions (reminiscent of data type definitions) * Racket also supports checked "contracts"

68 Racket (Scheme dialect) The Process: [..] 2. Write down a signature, [..] * HTDP encourages the use of function signatures as part of the design process. * It also uses data definitions (reminiscent of data type definitions) * Racket also supports checked "contracts"

69 -- QuickCheck prop_union s1 (s2 :: Set Int) = (s1 `union` s2) ==? (tolist s1 ++ tolist s2) * In formal specifications * But also useful for testing: QuickCheck * Popular specification-based testing framework»» And as the last example of a property

70 Logic formulas -- QuickCheck prop_union s1 (s2 :: Set Int) = (s1 `union` s2) ==? (tolist s1 ++ tolist s2) * In formal specifications * But also useful for testing: QuickCheck * Popular specification-based testing framework»» And as the last example of a property

71 -- return a >>= k == k a -- m >>= return == m -- m >>= (\x -> k x >>= h) -- == (m >>= k) >>= h class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a * Monads: categorial structures that needs to obey certain laws. * Think of them as API patterns.

72 Algebraic and categorial structures -- return a >>= k == k a -- m >>= return == m -- m >>= (\x -> k x >>= h) -- == (m >>= k) >>= h class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a * Monads: categorial structures that needs to obey certain laws. * Think of them as API patterns.

73 I/O in Haskell * Now that we have seen some examples of properties,...»»...let's look at an example of guiding a design by properties

74 Example of an uncompromising pursuit of properties I/O in Haskell * Now that we have seen some examples of properties,...»»...let's look at an example of guiding a design by properties

75 (not really Haskell) readname = let firstname = readstring () in let surname = readstring () in firstname ++ " " ++ surname * Read two strings from stdin and combine them. * In which order will firstname and surname be read? * Non-strict (or lazy) language: compute when needed»» Problem with I/O, as the following compiler optimisations demonstrate

76 (not really Haskell) readname = let firstname = readstring () in let surname = readstring () in firstname ++ " " ++ surname Haskell is a non-strict language * Read two strings from stdin and combine them. * In which order will firstname and surname be read? * Non-strict (or lazy) language: compute when needed»» Problem with I/O, as the following compiler optimisations demonstrate

77 readname = let firstname = readstring () in let surname = readstring () in firstname ++ " " ++ surname * Two occurences of the same lambda term must have the same meaning.

78 Common subexpression elimination readname = let firstname = readstring () in let surname = firstname readstring () in firstname ++ " " ++ surname * Two occurences of the same lambda term must have the same meaning.

79 readname = let firstname = readstring () in let surname = readstring () in firstname ++ " " ++ surname * No data depencency between the two bindings

80 Reordering readname = let surname firstname = readstring = () () in let firstname surname = = readstring () () in firstname ++ " " ++ surname * No data depencency between the two bindings

81 readname = let firstname = readstring () in let surname = readstring () in firstname * If a binding is not used, we should be able to eliminate it. * 1988: Haskell language committee faced the problem of mismatch between non-strictness and I/O»» They saw two options

82 Dead code elimination readname = let firstname = readstring () in let surname = readstring () in firstname * If a binding is not used, we should be able to eliminate it. * 1988: Haskell language committee faced the problem of mismatch between non-strictness and I/O»» They saw two options

83 Option ❶ Destroy purity»» To do so, they would need

84 » <Explain> Destroy purity

85 Destroy purity Prohibit those code transformations Enforce strict top to bottom evaluation of let bindings» <Explain>

86 Destroy purity Prohibit those code transformations Not a good idea! Enforce strict top to bottom evaluation of let bindings» <Explain>

87 WG 2.8, 1992 [This is not the real committee, but a large part.] * Didn't want to give up this property. * Non-strictness kept them honest.»» This left them with the second option

88 WG 2.8, 1992 Preserve those code transformations [This is not the real committee, but a large part.] * Didn't want to give up this property. * Non-strictness kept them honest.»» This left them with the second option

89 We want local reasoning Preserve those code transformations WG 2.8, 1992 [This is not the real committee, but a large part.] * Didn't want to give up this property. * Non-strictness kept them honest.»» This left them with the second option

90 We want local reasoning Preserve those code transformations WG 2.8, 1992 Think about concurrency [This is not the real committee, but a large part.] * Didn't want to give up this property. * Non-strictness kept them honest.»» This left them with the second option

91 We want local reasoning Preserve those code transformations WG 2.8, 1992 Keep purity! Think about concurrency [This is not the real committee, but a large part.] * Didn't want to give up this property. * Non-strictness kept them honest.»» This left them with the second option

92 Option ❷ Continuation-based & Stream-based I/O»» I don't want to explain them in detail, but here is an example

93 readname :: [Response] -> ([Request], String) readname ~(Str firstname : ~(Str surname : _)) = ([ReadChan stdin, ReadChan stdin], firstname ++ " " ++ surname) * Rather inconvenient programming model * Due to lack of a better idea, Haskell 1.0 to 1.2 used continuation-based and stream-based I/O»» Can't we do any better

94 readname :: [Response] -> ([Request], String) readname ~(Str firstname : ~(Str surname : _)) = ([ReadChan stdin, ReadChan stdin], firstname ++ " " ++ surname) readname :: FailCont -> StrCont -> Behaviour readname abort succ = readchan stdin abort (\firstname -> readchan stdin abort (\surname -> succ (firstname ++ " " ++ surname))) * Rather inconvenient programming model * Due to lack of a better idea, Haskell 1.0 to 1.2 used continuation-based and stream-based I/O»» Can't we do any better

95 What are the properties of I/O, of general stateful operations? * Let's take a step back.» Can we use properties to understand the nature of I/O?»» Let's characterise what stateful (imperative) computing is about

96 Arguments Result State changing function * In addition to arguments and result... *...state is threaded through.»» In the case of I/O

97 Arguments Result State State changing function State' * In addition to arguments and result... *...state is threaded through.»» In the case of I/O

98 Arguments Result I/O function * The state is the whole world»» How can we formalise this

99 Arguments Result I/O function * Categorial semantics of impure language features: properties of impure features * Lambda calculus with impure features * Characterise the meaning of effects»» How can we use that to write FPs

100 Arguments Result I/O function * Categorial semantics of impure language features: properties of impure features * Lambda calculus with impure features * Characterise the meaning of effects»» How can we use that to write FPs

101 Arguments Result Monad! I/O function Eugenio Moggi * Categorial semantics of impure language features: properties of impure features * Lambda calculus with impure features * Characterise the meaning of effects»» How can we use that to write FPs

102 Eugenio Moggi * Moggi's semantics is based on the lambda calculus * So, it ought to translate to FLs»» Finally, we can write our example program properly

103 Eugenio Moggi * Moggi's semantics is based on the lambda calculus * So, it ought to translate to FLs»» Finally, we can write our example program properly

104 Eugenio Moggi -- return a >>= k == k a -- m >>= return == m -- m >>= (\x -> k x >>= h) -- == (m >>= k) >>= h class Monad m where (>>=) :: m a -> (a -> m b) -> m b return :: a -> m a Philip Wadler instance Monad IO where... * Moggi's semantics is based on the lambda calculus * So, it ought to translate to FLs»» Finally, we can write our example program properly

105 (Real Haskell!) readname :: IO String readname = do firstname <- readstring surname <- readstring in return (firstname ++ " " ++ surname) * Development oriented at properties * Solution has an impact well beyond Haskell I/O»» Functional software development usually doesn't mean to resort to abstract math

106 Part 3 Applying the Methodology * So far, we saw that the genesis of FP resolved around working with and exploiting logical & mathematical properties.»» To get a feel for using such properties, let us look at a concrete development effort, where we used properties in many flavours to attack a difficult problem

107 Pure data parallelism»» Good parallel programming environments are important, because of

108 Case study in functional software development Pure data parallelism»» Good parallel programming environments are important, because of

109 Ubiquitous parallelism multicore CPU multicore GPU * Today, parallelism is everywhere! <Explain>»» We would like a parallel programming environment with meeting the following goals

110 Goal ➀ Exploit parallelism of commodity hardware easily: * We are not aiming at supercomputers * Ordinary applications cannot afford the resources that go into the development of HPC apps.»» To this end

111 Goal ➀ Exploit parallelism of commodity hardware easily: Performance is important, but productivity is more important. * We are not aiming at supercomputers * Ordinary applications cannot afford the resources that go into the development of HPC apps.»» To this end

112 Goal ➁ Semi-automatic parallelism: * Not fully automatic: computers cannot parallelise algos & seq algos are inefficient on parallel hardware. * Explicit concurrency is hard, non-modular, and error prone.»» How can properties help us to achieve these two goals

113 Goal ➁ Semi-automatic parallelism: Programmer supplies a parallel algorithm, but no explicit concurrency (no concurrency control, no races, no deadlocks). * Not fully automatic: computers cannot parallelise algos & seq algos are inefficient on parallel hardware. * Explicit concurrency is hard, non-modular, and error prone.»» How can properties help us to achieve these two goals

114 Three property-driven methods Types: track purity, generate array representations, guide optimisations State minimisation: localised state transformers, immutable structures Combinators: parallelisable aggregate array operations, exploit algebraic properties, restricted language for special hardware

115 Three property-driven methods Types Types: track purity, generate array representations, guide optimisations State minimisation: localised state transformers, immutable structures Combinators: parallelisable aggregate array operations, exploit algebraic properties, restricted language for special hardware

116 Three property-driven methods Types State minimisation Types: track purity, generate array representations, guide optimisations State minimisation: localised state transformers, immutable structures Combinators: parallelisable aggregate array operations, exploit algebraic properties, restricted language for special hardware

117 Three property-driven methods Types State minimisation Combinators & embedded languages Types: track purity, generate array representations, guide optimisations State minimisation: localised state transformers, immutable structures Combinators: parallelisable aggregate array operations, exploit algebraic properties, restricted language for special hardware

118 Ubiquitious parallelism multicore CPU multicore GPU»» What kind of code do we want to write for parallel hardware

119 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :]

120 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :]

121 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :] sm v

122 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :] sm v

123 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :] sm v

124 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :] Σ Σ Σ Σ Σ sm v

125 smvm :: SparseMatrix -> Vector -> Vector smvm sm v = [: sump (dotp sv v) sv <- sm :] Σ Σ Σ Σ Σ sm v

126 Types ensure purity, purity ensures non-interference. * Functions that are not of monadic type are pure. * Pure functions can execute in any order, also in parallel. => No concurrency control needed [Properties pay off Types.]»» But we need more than a convenient notation

127 Types Types ensure purity, purity ensures non-interference. * Functions that are not of monadic type are pure. * Pure functions can execute in any order, also in parallel. => No concurrency control needed [Properties pay off Types.]»» But we need more than a convenient notation

128 High performance * Performance is not the only goal, but it is a major goal. * Explain fluid flow.»» We can get good performance

129 * Repa (blue) is on 7 CPU cores (two quad-core Xenon E GHz, 64-bit) * Accelerate (green) is on a Tesla T10 processor ( GHz) * Repa talk: Ben Thursday before lunch * Accelerate talk: Trevor Friday before lunch

130 Jos Stam's Fluid Flow Solver * Repa (blue) is on 7 CPU cores (two quad-core Xenon E GHz, 64-bit) * Accelerate (green) is on a Tesla T10 processor ( GHz) * Repa talk: Ben Thursday before lunch * Accelerate talk: Trevor Friday before lunch

131 How do we achieve high performance from purely functional code?»» This presents an inherent tension

132 Unboxed, mutable arrays C-like loops»» We resolve this tension with local state

133 Performance Unboxed, mutable arrays C-like loops»» We resolve this tension with local state

134 Performance Unboxed, mutable arrays Pure C-like functions loops»» We resolve this tension with local state

135 Performance Parallelism & Optimisations Unboxed, mutable arrays Pure C-like functions loops»» We resolve this tension with local state

136 Performance Parallelism & Optimisations Unboxed, mutable arrays Pure C-like functions loops»» We resolve this tension with local state

137 (Pure) map :: (Shape sh, Source r a) => (a -> b) -> Array r sh a -> Array D sh b * We use a library of pure, parallel, aggregate operations * In Repa, types guide array representations»» Despite the pure interface, some combinators are internally impure

138 Types (Pure) map :: (Shape sh, Source r a) => (a -> b) -> Array r sh a -> Array D sh b * We use a library of pure, parallel, aggregate operations * In Repa, types guide array representations»» Despite the pure interface, some combinators are internally impure

139 Local state <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion

140 <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion Local state Allocate mutable array

141 <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion Local state Allocate mutable array Initialise destructively

142 <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion Local state Allocate mutable array Initialise destructively Freeze!

143 <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion State minimisation Local state Allocate mutable array Initialise destructively Freeze!

144 <Explain> * Program transformations and parallelisation on pure level * Then, unfold and optimise imperative program * Type system helps to get this right * Fusion Combinators Local state State minimisation Allocate mutable array Initialise destructively Freeze!

145 Special hardware 12 THREADS 24,576 THREADS Core i7 970 CPU NVIDIA GF100 GPU * Straight forward code generation is not suitable for all architectures»» GPUs are highly parallel, but also restricted in which operations are efficient

146 GPU's don't like * We won't compile all of Haskell to GPUs anytime soon.

147 GPU's don't like SIMD divergence (conditionals) * We won't compile all of Haskell to GPUs anytime soon.

148 GPU's don't like SIMD divergence (conditionals) Recursion * We won't compile all of Haskell to GPUs anytime soon.

149 GPU's don't like SIMD divergence (conditionals) Recursion Function pointers * We won't compile all of Haskell to GPUs anytime soon.

150 GPU's don't like SIMD divergence (conditionals) Recursion Function pointers Automatic garbage collection * We won't compile all of Haskell to GPUs anytime soon.

151 dotpacc :: Vector Float -> Vector Float -> Acc (Scalar Float) dotpacc xs ys = let xs' = use xs ys' = use ys in fold (+) 0 (zipwith (*) xs' ys') * We special purpose compile embedded code.

152 Acc marks embedded computations dotpacc :: Vector Float -> Vector Float -> Acc (Scalar Float) dotpacc xs ys = let xs' = use xs ys' = use ys in fold (+) 0 (zipwith (*) xs' ys') * We special purpose compile embedded code.

153 Acc marks embedded computations dotpacc :: Vector Float -> Vector Float -> Acc (Scalar Float) dotpacc xs ys = let xs' = use xs ys' = use ys in fold (+) 0 (zipwith (*) xs' ys') use embeds values * We special purpose compile embedded code.

154 Acc marks embedded computations Embedded language dotpacc :: Vector Float -> Vector Float -> Acc (Scalar Float) dotpacc xs ys = let xs' = use xs ys' = use ys in fold (+) 0 (zipwith (*) xs' ys') use embeds values * We special purpose compile embedded code.

155 types >< state languages

156 Functional programming is fundamental to computing Functional software development is property-driven development types >< state languages

157 Thank you!

158 Images from

DATA PARALLEL PROGRAMMING IN HASKELL

DATA PARALLEL PROGRAMMING IN HASKELL DATA PARALLEL PROGRAMMING IN HASKELL An Overview Manuel M T Chakravarty University of New South Wales INCLUDES JOINT WORK WITH Gabriele Keller Sean Lee Roman Leshchinskiy Ben Lippmeier Trevor McDonell

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

Introduction to Functional Programming and Haskell. Aden Seaman

Introduction to Functional Programming and Haskell. Aden Seaman Introduction to Functional Programming and Haskell Aden Seaman Functional Programming Functional Programming First Class Functions Expressions (No Assignment) (Ideally) No Side Effects Different Approach

More information

Software System Design and Implementation

Software System Design and Implementation Software System Design and Implementation Motivation & Introduction Gabriele Keller (Manuel M. T. Chakravarty) The University of New South Wales School of Computer Science and Engineering Sydney, Australia

More information

Chapter 11 :: Functional Languages

Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Copyright 2016 Elsevier 1 Chapter11_Functional_Languages_4e - Tue November 21, 2017 Historical Origins The imperative

More information

Programming Language Pragmatics

Programming Language Pragmatics Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen

More information

Introduction. chapter Functions

Introduction. chapter Functions chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main

More information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

Software System Design and Implementation

Software System Design and Implementation Software System Design and Implementation Admin & Motivation & Some History Gabriele Keller Admin: Liam O Connor-Davies The University of New South Wales School of Computer Science and Engineering Sydney,

More information

CS457/557 Functional Languages

CS457/557 Functional Languages CS457/557 Functional Languages Spring 2018 Lecture 1: Course Introduction Andrew Tolmach Portland State University (with thanks to Mark P. Jones) 1 Goals of this course Introduce the beautiful ideas of

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

Text. Parallelism Gabriele Keller University of New South Wales

Text. Parallelism Gabriele Keller University of New South Wales Text Parallelism Gabriele Keller University of New South Wales Programming Languages Mentoring Workshop 2015 undergrad Karslruhe & Berlin, Germany PhD Berlin & Tsukuba, Japan University of Technology Sydney

More information

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University

Functional Languages. CSE 307 Principles of Programming Languages Stony Brook University Functional Languages CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Historical Origins 2 The imperative and functional models grew out of work

More information

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Haskell Basics 1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Basics 2 Contents 1. Jump into Haskell: Using ghc and ghci (more detail) 2. Historical Background of Haskell 3. Lazy, Pure, and Functional

More information

4/19/2018. Chapter 11 :: Functional Languages

4/19/2018. Chapter 11 :: Functional Languages Chapter 11 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken by Alan Turing, Alonzo Church, Stephen

More information

Functional Programming

Functional Programming The Meta Language (ML) and Functional Programming Daniel S. Fava danielsf@ifi.uio.no Department of informatics University of Oslo, Norway Motivation ML Demo Which programming languages are functional?

More information

Less naive type theory

Less naive type theory Institute of Informatics Warsaw University 26 May 2007 Plan 1 Syntax of lambda calculus Why typed lambda calculi? 2 3 Syntax of lambda calculus Why typed lambda calculi? origins in 1930s (Church, Curry)

More information

Stop coding Pascal. Saturday, April 6, 13

Stop coding Pascal. Saturday, April 6, 13 Stop coding Pascal...emotional sketch about past, present and future of programming languages, Python, compilers, developers, Life, Universe and Everything Alexey Kachayev CTO at KitApps Inc. Open source

More information

Programming Systems in Artificial Intelligence Functional Programming

Programming Systems in Artificial Intelligence Functional Programming Click to add Text Programming Systems in Artificial Intelligence Functional Programming Siegfried Nijssen 8/03/16 Discover thediscover world at the Leiden world University at Leiden University Overview

More information

Lecture 8: Summary of Haskell course + Type Level Programming

Lecture 8: Summary of Haskell course + Type Level Programming Lecture 8: Summary of Haskell course + Type Level Programming Søren Haagerup Department of Mathematics and Computer Science University of Southern Denmark, Odense October 31, 2017 Principles from Haskell

More information

Functional Programming

Functional Programming Functional Programming Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Brief

More information

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes Welcome to CS 470/670 Introduction to Artificial Intelligence Office: Lab: Instructor Marc Pomplun S-3-171 S-3-135 Office Hours: Tuesdays 4:00pm 5:30pm Thursdays 7:00pm 8:30pm Spring 2016 Instructor: Marc

More information

A Pragmatic Case For. Static Typing

A Pragmatic Case For. Static Typing A Pragmatic Case For Static Typing Slides available from github at: https://github.com/bhurt/presentations/blob/master /statictyping.odp Please Hold your Comments, Criticisms, Objections, Etc. To the end

More information

Introduction to the Lambda Calculus. Chris Lomont

Introduction to the Lambda Calculus. Chris Lomont Introduction to the Lambda Calculus Chris Lomont 2010 2011 2012 www.lomont.org Leibniz (1646-1716) Create a universal language in which all possible problems can be stated Find a decision method to solve

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

Lambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6

Lambda calculus. Wouter Swierstra and Alejandro Serrano. Advanced functional programming - Lecture 6 Lambda calculus Advanced functional programming - Lecture 6 Wouter Swierstra and Alejandro Serrano 1 Today Lambda calculus the foundation of functional programming What makes lambda calculus such a universal

More information

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes

Chapter 13: Reference. Why reference Typing Evaluation Store Typings Safety Notes Chapter 13: Reference Why reference Typing Evaluation Store Typings Safety Notes References Computational Effects Also known as side effects. A function or expression is said to have a side effect if,

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012 CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our

More information

Lambda Calculus.

Lambda Calculus. Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto, Stephen A. Edwards) Benjamin Pierce Types and Programming Languages http://www.cs.cornell.edu/courses/cs3110/2008fa/recitations/rec26.html

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages Haskell 101 Dr. Hyunyoung Lee 1 Contents 1. Historical Background of Haskell 2. Lazy, Pure, and Functional Language 3. Using ghc and ghci 4. Functions 5. Haskell Scripts

More information

Functional Programming Principles in Scala. Martin Odersky

Functional Programming Principles in Scala. Martin Odersky Functional Programming Principles in Scala Martin Odersky Programming Paradigms Paradigm: In science, a paradigm describes distinct concepts or thought patterns in some scientific discipline. Main programming

More information

FUNCTIONAL PEARLS The countdown problem

FUNCTIONAL PEARLS The countdown problem To appear in the Journal of Functional Programming 1 FUNCTIONAL PEARLS The countdown problem GRAHAM HUTTON School of Computer Science and IT University of Nottingham, Nottingham, UK www.cs.nott.ac.uk/

More information

Concepts of program design Exam January 31, 13:30 16:30

Concepts of program design Exam January 31, 13:30 16:30 Concepts of program design 2016 2017 Exam January 31, 13:30 16:30 Name: Student number: Please read the following instructions carefully: Fill in your name and student number above. Be prepared to identify

More information

Lecture 5: The Untyped λ-calculus

Lecture 5: The Untyped λ-calculus Lecture 5: The Untyped λ-calculus Syntax and basic examples Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Static Analysis Pratikakis (CSD) Untyped λ-calculus I CS49040,

More information

Programming with Math and Logic

Programming with Math and Logic .. Programming with Math and Logic an invitation to functional programming Ed Morehouse Wesleyan University The Plan why fp? terms types interfaces The What and Why of Functional Programming Computing

More information

Background Type Classes (1B) Young Won Lim 6/28/18

Background Type Classes (1B) Young Won Lim 6/28/18 Background Type Classes (1B) Copyright (c) 2016-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Lambda Calculus. Variables and Functions. cs3723 1

Lambda Calculus. Variables and Functions. cs3723 1 Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can

More information

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Advanced Topics in Programming Languages Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and Programming

More information

3. Functional Programming. Oscar Nierstrasz

3. Functional Programming. Oscar Nierstrasz 3. Functional Programming Oscar Nierstrasz Roadmap > Functional vs. Imperative Programming > Pattern Matching > Referential Transparency > Lazy Evaluation > Recursion > Higher Order and Curried Functions

More information

Software System Design and Implementation

Software System Design and Implementation Software System Design and Implementation Functional Programming Gabriele Keller The University of New South Wales School of Computer Science and Engineering Sydney, Australia COMP3141 16s1 Course software

More information

Functional Programming Patterns And Their Role Instructions

Functional Programming Patterns And Their Role Instructions Functional Programming Patterns And Their Role Instructions In fact, the relabelling function is precisely the same as before! Phil Wadler's Chapter 7 of The Implementation of Functional Programming Languages.

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

From the λ-calculus to Functional Programming Drew McDermott Posted

From the λ-calculus to Functional Programming Drew McDermott Posted From the λ-calculus to Functional Programming Drew McDermott drew.mcdermott@yale.edu 2015-09-28 Posted 2015-10-24 The λ-calculus was intended from its inception as a model of computation. It was used by

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Untyped Lambda Calculus

Untyped Lambda Calculus Concepts in Programming Languages Recitation 5: Untyped Lambda Calculus Oded Padon & Mooly Sagiv (original slides by Kathleen Fisher, John Mitchell, Shachar Itzhaky, S. Tanimoto ) Reference: Types and

More information

CIS 500 Software Foundations Fall September 25

CIS 500 Software Foundations Fall September 25 CIS 500 Software Foundations Fall 2006 September 25 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial programming language, then the

More information

Behavioral Equivalence

Behavioral Equivalence Behavioral Equivalence Prof. Clarkson Fall 2015 Today s music: Soul Bossa Nova by Quincy Jones Review Previously in 3110: Functional programming Modular programming Interpreters Imperative and concurrent

More information

Is Functional Programming (FP) for me? ACCU Conference 2008 Hubert Matthews

Is Functional Programming (FP) for me? ACCU Conference 2008 Hubert Matthews Is Functional Programming (FP) for me? ACCU Conference 2008 Hubert Matthews hubert@oxyware.com Overview of talk History of computing Types of problem, developers, solution, environments, managers Pros

More information

Software System Design and Implementation

Software System Design and Implementation Software System Design and Implementation Controlling Effects Gabriele Keller The University of New South Wales School of Computer Science and Engineering Sydney, Australia COMP3141 18s1 Examples of effects

More information

Lecture 5: The Halting Problem. Michael Beeson

Lecture 5: The Halting Problem. Michael Beeson Lecture 5: The Halting Problem Michael Beeson Historical situation in 1930 The diagonal method appears to offer a way to extend just about any definition of computable. It appeared in the 1920s that it

More information

A Theory of Parallel Computation The π-calculus

A Theory of Parallel Computation The π-calculus A Theory of Parallel Computation The π-calculus Background DFAs, NFAs, pushdown automata, Turing machines... All are mathematical entities that model computation. These abstract systems have concrete,

More information

Optimising Functional Programming Languages. Max Bolingbroke, Cambridge University CPRG Lectures 2010

Optimising Functional Programming Languages. Max Bolingbroke, Cambridge University CPRG Lectures 2010 Optimising Functional Programming Languages Max Bolingbroke, Cambridge University CPRG Lectures 2010 Objectives Explore optimisation of functional programming languages using the framework of equational

More information

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion

Recursion. Lecture 6: More Lambda Calculus Programming. Fixed Points. Recursion Recursion Lecture 6: More Lambda Calculus Programming CSC 131! Fall, 2014!! Kim Bruce Recursive definitions are handy! - fact = λn. cond (iszero n) 1 (Mult n (fact (Pred n)))! - Not a legal definition

More information

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland

COMP 1130 Lambda Calculus. based on slides by Jeff Foster, U Maryland COMP 1130 Lambda Calculus based on slides by Jeff Foster, U Maryland Motivation Commonly-used programming languages are large and complex ANSI C99 standard: 538 pages ANSI C++ standard: 714 pages Java

More information

J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died

J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died Church-Rosser J. Barkley Rosser, 81, a professor emeritus of mathematics and computer science at the University of Wisconsin who had served in government, died Sept. 5, 1989. Along with Alan Turing and

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 1 Programming Language Features Many features exist simply for convenience Multi-argument functions foo ( a, b, c ) Use currying

More information

Monads in Haskell. Nathanael Schilling. December 12, 2014

Monads in Haskell. Nathanael Schilling. December 12, 2014 Monads in Haskell Nathanael Schilling December 12, 2014 Abstract In Haskell, monads provide a mechanism for mapping functions of the type a -> m b to those of the type m a -> m b. This mapping is dependent

More information

CMSC330. Objects, Functional Programming, and lambda calculus

CMSC330. Objects, Functional Programming, and lambda calculus CMSC330 Objects, Functional Programming, and lambda calculus 1 OOP vs. FP Object-oriented programming (OOP) Computation as interactions between objects Objects encapsulate mutable data (state) Accessed

More information

Introduction to Functional Programming

Introduction to Functional Programming PART I TE RI AL Introduction to Functional Programming MA CHAPTER 1: A Look at Functional Programming History CO PY RI GH TE D CHAPTER 2: Putting Functional Programming into a Modern Context 1A Look at

More information

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona 1/37 CSc 372 Comparative Programming Languages 2 : Functional Programming Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/37 Programming Paradigms

More information

Software System Design and Implementation

Software System Design and Implementation Software System Design and Implementation Property-based Testing Gabriele Keller The University of New South Wales School of Computer Science and Engineering Sydney, Australia COMP3141 17s1 Testing in

More information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

The Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer

The Eval/Apply Cycle Eval. Evaluation and universal machines. Examining the role of Eval. Eval from perspective of language designer Evaluation and universal machines What is the role of evaluation in defining a language? How can we use evaluation to design a language? The Eval/Apply Cycle Eval Exp & env Apply Proc & args Eval and Apply

More information

Programming Proofs and Proving Programs. Nick Benton Microsoft Research, Cambridge

Programming Proofs and Proving Programs. Nick Benton Microsoft Research, Cambridge Programming Proofs and Proving Programs Nick Benton Microsoft Research, Cambridge Coffee is does Greek 1. To draw a straight line from any point to any point. 2. To produce a finite straight line continuously

More information

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures Dan Grossman Fall 2014 Hi! I m not Hal J I love this stuff and have taught

More information

COS 326 Functional programming: an elegant weapon for the modern age

COS 326 Functional programming: an elegant weapon for the modern age COS 326 Functional programming: an elegant weapon for the modern age In 1936, Alonzo Church invented the lambda calculus. He called it a logic, but it was a language of pure functions -- the world's first

More information

Introduction to OCaml

Introduction to OCaml Fall 2018 Introduction to OCaml Yu Zhang Course web site: http://staff.ustc.edu.cn/~yuzhang/tpl References Learn X in Y Minutes Ocaml Real World OCaml Cornell CS 3110 Spring 2018 Data Structures and Functional

More information

Type Systems Winter Semester 2006

Type Systems Winter Semester 2006 Type Systems Winter Semester 2006 Week 4 November 8 November 15, 2006 - version 1.1 The Lambda Calculus The lambda-calculus If our previous language of arithmetic expressions was the simplest nontrivial

More information

Trees. Solution: type TreeF a t = BinF t a t LeafF 1 point for the right kind; 1 point per constructor.

Trees. Solution: type TreeF a t = BinF t a t LeafF 1 point for the right kind; 1 point per constructor. Trees 1. Consider the following data type Tree and consider an example inhabitant tree: data Tree a = Bin (Tree a) a (Tree a) Leaf deriving Show tree :: Tree Int tree = Bin (Bin (Bin Leaf 1 Leaf ) 2 (Bin

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming About the Tutorial Haskell is a widely used purely functional language. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional

More information

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing What Is Computer Science? The Scientific Study of Computation CMPSCI 630: Programming Languages Introduction Spring 2009 (with thanks to Robert Harper) Expressing or Describing Automating Understanding

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 15 - Functional Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

The Untyped Lambda Calculus

The Untyped Lambda Calculus Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn

More information

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods

λ calculus Function application Untyped λ-calculus - Basic Idea Terms, Variables, Syntax β reduction Advanced Formal Methods Course 2D1453, 2006-07 Advanced Formal Methods Lecture 2: Lambda calculus Mads Dam KTH/CSC Some material from B. Pierce: TAPL + some from G. Klein, NICTA Alonzo Church, 1903-1995 Church-Turing thesis First

More information

Introduction to Functional Programming in Haskell 1 / 56

Introduction to Functional Programming in Haskell 1 / 56 Introduction to Functional Programming in Haskell 1 / 56 Outline Why learn functional programming? The essence of functional programming What is a function? Equational reasoning First-order vs. higher-order

More information

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals

Review. CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Let bindings (CBV) Adding Stuff. Booleans and Conditionals Review CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics e ::= λx. e x ee c v ::= λx. e c (λx. e) v e[v/x] e 1 e 2 e 1 e 2 τ ::= int τ τ Γ ::= Γ,x : τ e 2 e 2 ve 2 ve 2 e[e /x]:

More information

CS The IO Monad. Slides from John Mitchell, K Fisher, and S. Peyton Jones

CS The IO Monad. Slides from John Mitchell, K Fisher, and S. Peyton Jones CS 242 2012 The IO Monad Slides from John Mitchell, K Fisher, and S. Peyton Jones Reading: Tackling the Awkward Squad, Sections 1-2 Real World Haskell, Chapter 7: I/O Beauty... Functional programming is

More information

Haskell Monads CSC 131. Kim Bruce

Haskell Monads CSC 131. Kim Bruce Haskell Monads CSC 131 Kim Bruce Monads The ontological essence of a monad is its irreducible simplicity. Unlike atoms, monads possess no material or spatial character. They also differ from atoms by their

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Lambda Calculus CMSC 330 Summer 2017 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

Towards Reasoning about State Transformer Monads in Agda. Master of Science Thesis in Computer Science: Algorithm, Language and Logic.

Towards Reasoning about State Transformer Monads in Agda. Master of Science Thesis in Computer Science: Algorithm, Language and Logic. Towards Reasoning about State Transformer Monads in Agda Master of Science Thesis in Computer Science: Algorithm, Language and Logic Viet Ha Bui Department of Computer Science and Engineering CHALMERS

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Value Recursion in Monadic Computations

Value Recursion in Monadic Computations Value Recursion in Monadic Computations Levent Erkök OGI School of Science and Engineering, OHSU Advisor: John Launchbury June 24th, 2002 Outline Recursion and effects Motivating examples Value recursion

More information

Anders Møller Michael Schwartzbach Erik Ernst Hans Hüttel

Anders Møller Michael Schwartzbach Erik Ernst Hans Hüttel Programming Paradigms 2010 Anders Møller Michael Schwartzbach Erik Ernst Hans Hüttel Aims This purpose of the course is to introduce the student to programming g languages g that support a variety of programming

More information

Programming Languages Fall Prof. Liang Huang

Programming Languages Fall Prof. Liang Huang Programming Languages Fall 2014 Prof. Liang Huang huang@qc.cs.cuny.edu Computer Science is no more about computers than astronomy is about telescopes. (Mis)attributed to Edsger Dijkstra, 1970. Computer

More information

CMSC 330: Organization of Programming Languages. Lambda Calculus

CMSC 330: Organization of Programming Languages. Lambda Calculus CMSC 330: Organization of Programming Languages Lambda Calculus 1 100 years ago Albert Einstein proposed special theory of relativity in 1905 In the paper On the Electrodynamics of Moving Bodies 2 Prioritätsstreit,

More information

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08

Introduction to Lambda Calculus. Lecture 5 CS 565 1/24/08 Introduction to Lambda Calculus Lecture 5 CS 565 1/24/08 Lambda Calculus So far, we ve explored some simple but non-interesting languages language of arithmetic expressions IMP (arithmetic + while loops)

More information

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21

Functions as data. Massimo Merro. 9 November Massimo Merro The Lambda language 1 / 21 Functions as data Massimo Merro 9 November 2011 Massimo Merro The Lambda language 1 / 21 The core of sequential programming languages In the mid 1960s, Peter Landin observed that a complex programming

More information

Programming Languages

Programming Languages Programming Languages Andrea Flexeder Chair for Theoretical Computer Science Prof. Seidl TU München winter term 2010/2011 Lecture 10 Side-Effects Main Points you should get: Why monads? What is a monad?

More information

Behavioral Equivalence

Behavioral Equivalence Behavioral Equivalence Prof. Clarkson Fall 2016 Today s music: Soul Bossa Nova by Quincy Jones Review Previously in 3110: Functional programming Modular programming & software engineering Interpreters

More information

CS 6110 S14 Lecture 1 Introduction 24 January 2014

CS 6110 S14 Lecture 1 Introduction 24 January 2014 CS 6110 S14 Lecture 1 Introduction 24 January 2014 1 Introduction What is a program? Is it just something that tells the computer what to do? Yes, but there is much more to it than that. The basic expressions

More information

As Natural as 0, 1, 2. Philip Wadler University of Edinburgh

As Natural as 0, 1, 2. Philip Wadler University of Edinburgh As Natural as 0, 1, 2 Philip Wadler University of Edinburgh wadler@inf.ed.ac.uk Haskell Hindley-Milner types Java Girard-Reynolds types XML Operational semantics Part 0 Counting starts at zero Carle Carle

More information