D7020E. Robust and Energy-Efficient Real-Time Systems D7020E. Lecture 2: Components & the Timber language

Size: px
Start display at page:

Download "D7020E. Robust and Energy-Efficient Real-Time Systems D7020E. Lecture 2: Components & the Timber language"

Transcription

1 Robust and Energy-Efficient Real-Time Systems Lecture 2: Components & the Timber language 1 1

2 Recall The dynamic evolution of a system... with offset asynchronous calls synchronous call T T blocked buffered Time?? 2 2

3 Also recall The static structure of a system?? The blocks look like components in an electronic circuit diagram

4 Components... A frequently used term in software engineering Not always well-defined... Still a very appealing engineering concept (c.f. electronic components) Many similarities to objects: Data encapsulation Functional encapsulation Access via interfaces only However, the essence of components usually means Context-independence resuability mass production! 4 4

5 A source of confusion Objects are unique run-time instances, they can't be reused A component must mean a class instead... However, classes usually refer to other classes and definitions in scope, can't be used outside their context Maybe a component should mean a module... But modules usually contain global state variables should these be duplicated or not when components are mass-produced? So a module is just like a fancy object? 5 5

6 More confusion How is concurrent execution related to components? Is a component equivalent to a thread? What is the functional interface to a component? A set of procedures? What about synchronization? What about underlying OS dependencies? Can components be distributed? (Well, they ought to!) Then what is the protocol? Remote-procedure-calls? How are component interfaces specified? What kind of types are allowed? Behavior specifications? Logic? Should timing properties be part of an interface? 6 6

7 Enter Timber (timber-lang.org) A high-level programming language, built around the same programming model as TinyTimber: Event-triggered execution = the classic object-oriented paradigm revisited! In addition: Dynamic object creation Garbage-collecting memory management Strong static type system including subtyping, parametric polymorphism, dynamic overloading,... Rich assortment of immutable & higher-order data 7 7

8 Timber and components A split view: When we engineer systems we think of components as objects unique instances each with a private state What we really mean, though, are classes and not objects, and that's what we write as program code However, when it comes to reusability and massproduction, a Timber component is a module: Definitions of classes, functions and other constants Definitions of types But no mutable variables modules can be freely duplicated, shared, reused, cached, packaged as binaries...! 8 8

9 No declared global state! State variables only exist within objects And only classes (i.e., object generators) written in code Classes may instantiate other classes, but only when they become instantiated themselves Q: So how does this process start? Where is the root of the whole program instantiated? A: In the run-time system, on basis of a class name given as an argument to the compiler (default: root) C.f. "Where does the function call-chain start in C? In the run-time system, based on a name convention" 9 9

10 Timber code vs. Timber at run-time module A where module E where map f [] = [] map f (x:xs) = f x : map f xs myapp arg = class... id x = x module F module B module D module I module J module H where module G where counter = class val := 0 inc = action val := val + 1 aaa = 123 read = request result val module C Immutable reusable Timber modules module K where anotherapp env = class result Counter {..} Mutable unique Timber "worlds" root = E.myApp root = E.myApp root = K.anotherApp 10 10

11 Run-time execution model Mutually exclusive In parallel Object A Local state Object B Method 1 External events Method 2 Local state Asynchronous Messages Synch ronou s Asynchronous Method 3 Method 4 External reactions delayed 11 11

12 Methods Local state Method Method Finite sequences that Read and write local state Call other methods Create new objects Perform pure computations No indefinitely blocking operations, no infinite loops: objects sleep between temporary activity The classical OO intuition recast to a concurrent setting! 12 12

13 A simple event counter struct Counter where interface spec automatically inc :: Action inferred type read :: Request Int counter :: Class Counter an object generator counter = class val := 0 asynchronous method local state inc = action val := val + 1 synchronous method read = request result val result Counter { inc = inc, read = read } struct stuffing 13 13

14 A simple event counter val :: Int inc read 14 14

15 Using the simple event counter Somewhere in the code:... c = new counter... c.inc... c.inc... v <- c.read if v == 2 then... object creation asynchronous method call synchronous method call, binds result to v 15 15

16 Variant: a buffer A type parameter val :: [a] insert read struct Buffer a where insert :: a -> Action read :: Request [a] Method taking an argument List type List buffer = class construction val := [] insert x = action val := x : val read = request result val result Buffer {..} 16 16

17 An extended buffer class Declared subtyping (type extension) val :: [a] insert read clear struct CBuffer a < Buffer a where clear :: Action buffer2 = class val := [] insert x = action val := x : val read = request result val clear = action val := [] result CBuffer {..} 17 17

18 Alternative: a flush buffer struct FlushBuf a where insert :: a -> Action flush :: Action val :: [a] insert flush fbuf :: ([a]->action) -> Class (FlushBuf a) fbuf consumer = class val := [] insert x = action? val := x : val flush = action consumer val val := [] result FlushBuf {..} A required interface 18 18

19 In general method1... methodn Provided interface Often a struct... Required interface Often a struct

20 In general method1... methodn Provided interfaces Required interfaces Can also be (a tuple of) individual methods Or any data structure containing methods! 20 20

21 On data structures All data are not objects! In fact, Timber offers a wealth of immutable data: Lists User-defined structs User-defined unions (tagged alternatives) Tuples of any width Arrays (become mutable when part of object state) Functions (first-class citizens) First-class methods, classes and commands Objects only for capturing the state of a system 21 21

22 Timber & Haskell As is syntactically obvious, Timber is a descendant of Haskell ( Shares purely functional basis, strong typing principle, overloading system, many syntactic details Differences in Timber: Objects, methods & classes not part of Haskell (which has a more traditional imperative top-level) Event-triggered concurrency & timing Standard strict expression evaluation (as opposed to Haskell's lazy semantics) Subtyping & user-defined structs 22 22

23 Lists Basic constructors: [] (the empty list) x:xs (x put in front of list xs) Syntactic shorthand: [a,b,c,d] equivalent to a:b:c:d:[] Analysis via pattern-matching & recursion: length [] =0 length (x:xs) = 1 + length xs Concatenation (a standard operator): [] ++ ys = ys (x:xs) ++ ys = x : (xs ++ ys) 23 23

24 On syntax Function calls don't need parentheses: length xs (call length with argument xs) sin (alpha+1.0) (call sin with argument alpha+1.0) min a b (call min with arguments a and b) Operators are just infix functions with symbolic names: a+b (call + with arguments a and b) (a+b) * sin y (call * with arguments a+b and sin y) Odinary calls always bind harder than operators Operators have their "usual" precedence Parentheses override any precedence 24 24

25 User-defined structs Introduced by declaration: struct Complex where re :: Float im :: Float Also declares selectors re and im Makes Complex distinct from any other type Constructing struct terms: Complex { re = 2.1, im = 5.0 } { re = 2.1, im = 5.0 } Full form When selectors identify the type Accessing fields: x.re * x.re + x.im * x.im 25 25

26 User-defined unions Introduced by declaration: data Color = Red Blue Green Construction (just say Blue, for example) and analysis: case x of Red -> 0 Blue -> 1 Green -> 2 Or, by means of a defined function: ff Red = 0 ff Blue = 1 ff Green =

27 User-defined unions Constructors with arguments: data IntOrBool = Itag Int Btag Bool Term construction is just application: Itag 87 or Itag 0 or Btag False Analysis by pattern-matching: explain (Itag 0) = "zero" explain (Itag _) = "non-zero" explain (Btag True) = "true" explain (Btag False) = "false" 27 27

28 Higher-order functions Mapping a function onto a list of arguments: map f [] = [] map f (x:xs) = f x : map f xs Example of use: successor n =n+1 ys = map successor [1,2,3] Alternatively, using an anonymous function: ys = map (\n -> n+1) [1,2,3] 28 28

29 Overloading Declaring overloaded equality operators: typeclass Eq a where (==),(/=) :: a -> a -> Bool Making them defined for types Int and Char: instance eqint :: Eq Int where (==) = priminteq (/=) = primintne instance eqchar :: Eq Char where a == b = ord a == ord b a /= b = ord a /= ord b 29 29

30 Polymorphic overloading Open use of overloaded operators: elem x [] = False elem x (y:ys) = x == y elem x ys What would be a proper type for elem? elem :: Int -> [Int] -> Bool Too specific elem :: Char -> [Char] -> Bool Too specific elem :: a -> [a] -> Bool Too general Solution borrowed from Haskell: add a class constraint! elem :: a -> [a] -> Bool \\ Eq a (Note deviation from Haskell syntax, though) 30 30

31 Pure computations Compare with f1 x = g x + g x f2 x = let y = g x in y + y In Timber, f1 and f2 are provably identical, for all g! In C, they would be different if g contains effects: int g (int v) { printf("hello!"); return v*v; } Timber distinguishes between effects and pure computations by means of types: Int -> Int Int -> Request Int Pure functions from Int to Int Methods from Int to Int 31 31

32 Commands Timber has four forms of bindings/assignments: x = exp x is defined equal to the value of exp x = new exp x is defined equal to the result of instantiating class expression exp x <- exp x is defined equal to the result of executing method expression exp x := exp x is modified to become equal to exp (x must be a state variable in scope) Only the first two forms may be recursive Form x <- exp may not occur in class bodies 32 32

33 Examples Simple value bindings: incby4 = \v -> v+4 seven = incby4 3 Syntactic short-hand for function values: incby4 v = v+4 Non-recursive mutation of state variable s: s := incby4 s Mutually recursive object instances: a = new classa b b = new classb a 33 33

34 Easy mistakes Unintended recursive binding (rejected): meth x = action x = incby4 x (Solution: call local variable something else than x!) Confusing a method with its result: x = obj.meth arg y=x+x (Solution: write x <- obj.meth arg to capture result!) Use of instantiation as an expression: x = f (new myclass) (Solution: write y = new myclass as a separate binding) 34 34

35 A sonar example alarm reset stop sample echo interrupt port ping start 35 35

36 A sonar example sonar port alarm critical = class tm = new timer A built-in class for measuring A local object count := 0 time ping = action port.write beepon tm.reset after (millisec 2) stop after (sec 3) ping stop = action port.write beepoff Returns time since last reset echo = action diff <- tm.sample if critical diff then count := count + 1 A function parameter alarm count result { interrupt = echo, start = ping } 36 36

37 The sonar program root regs sonar interrupts alarm 37 37

38 The sonar program root The required interface (Here: an array of ports) A boolean function passed as a parameter root regs = class crit d = d < millisec 15 a = new alarm (regs! comportaddr) s = new sonar (regs! sonarportaddr) a crit result [ s.start, s.interrupt, a.ack ] The provided interface (Here: a list of interrupt handlers) 38 38

39 The root under POSIX The required interface (Here: a struct of OS services) root env = class a = new b result action... env.stdin.installr a.keyhandler... The provided interface (Here: just a startup method main) 39 39

D7020E. The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems. blocked Lecture 2: Components & the Timber language.

D7020E. The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems. blocked Lecture 2: Components & the Timber language. Recall The dynamic evolution of a system Robust and Energy-Efficient Real-Time Systems with offset asynchronous calls synchronous call T T blocked Lecture 2: Components & the Timber language buffered??

More information

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder

Haskell Introduction Lists Other Structures Data Structures. Haskell Introduction. Mark Snyder Outline 1 2 3 4 What is Haskell? Haskell is a functional programming language. Characteristics functional non-strict ( lazy ) pure (no side effects*) strongly statically typed available compiled and interpreted

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

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

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

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program

More information

An introduction introduction to functional functional programming programming using usin Haskell

An introduction introduction to functional functional programming programming using usin Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program

More information

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis

More information

Haskell Types, Classes, and Functions, Currying, and Polymorphism

Haskell Types, Classes, and Functions, Currying, and Polymorphism 1 CSCE 314: Programming Languages Dr. Flemming Andersen Haskell Types, Classes, and Functions, Currying, and Polymorphism 2 Types A type is a collection of related values. For example, Bool contains the

More information

Overloading, Type Classes, and Algebraic Datatypes

Overloading, Type Classes, and Algebraic Datatypes Overloading, Type Classes, and Algebraic Datatypes Delivered by Michael Pellauer Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. September 28, 2006 September 28, 2006 http://www.csg.csail.mit.edu/6.827

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309 A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48

More information

INTRODUCTION TO HASKELL

INTRODUCTION TO HASKELL INTRODUCTION TO HASKELL PRINCIPLES OF PROGRAMMING LANGUAGES Norbert Zeh Winter 2018 Dalhousie University 1/81 HASKELL: A PURELY FUNCTIONAL PROGRAMMING LANGUAGE Functions are first-class values: Can be

More information

n n Try tutorial on front page to get started! n spring13/ n Stack Overflow!

n   n Try tutorial on front page to get started! n   spring13/ n Stack Overflow! Announcements n Rainbow grades: HW1-6, Quiz1-5, Exam1 n Still grading: HW7, Quiz6, Exam2 Intro to Haskell n HW8 due today n HW9, Haskell, out tonight, due Nov. 16 th n Individual assignment n Start early!

More information

According to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe!

According to Larry Wall (designer of PERL): a language by geniuses! for geniuses. Lecture 7: Haskell. Haskell 98. Haskell (cont) - Type-safe! Lecture 7: Haskell CSC 131 Fall, 2014 Kim Bruce According to Larry Wall (designer of PERL): a language by geniuses for geniuses He s wrong at least about the latter part though you might agree when we

More information

CSE 3302 Programming Languages Lecture 8: Functional Programming

CSE 3302 Programming Languages Lecture 8: Functional Programming CSE 3302 Programming Languages Lecture 8: Functional Programming (based on the slides by Tim Sheard) Leonidas Fegaras University of Texas at Arlington CSE 3302 L8 Spring 2011 1 Functional Programming Languages

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

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

A general introduction to Functional Programming using Haskell

A general introduction to Functional Programming using Haskell A general introduction to Functional Programming using Haskell Matteo Rossi Dipartimento di Elettronica e Informazione Politecnico di Milano rossi@elet.polimi.it 1 Functional programming in a nutshell

More information

CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

More information

An introduction to functional programming. July 23, 2010

An introduction to functional programming. July 23, 2010 An introduction to functional programming July 23, 2010 About Outline About About What is functional programming? What is? Why functional programming? Why? is novel. is powerful. is fun. About A brief

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

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

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

CSC324 Principles of Programming Languages

CSC324 Principles of Programming Languages CSC324 Principles of Programming Languages http://mcs.utm.utoronto.ca/~324 November 14, 2018 Today Final chapter of the course! Types and type systems Haskell s type system Types Terminology Type: set

More information

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! CPSC 449 Principles of Programming Languages Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

More information

Programming Languages Fall 2013

Programming Languages Fall 2013 Programming Languages Fall 2013 Lecture 2: types Prof. Liang Huang huang@qc.cs.cuny.edu Recap of Lecture 1 functional programming vs. imperative programming basic Haskell syntax function definition lazy

More information

Course year Typeclasses and their instances

Course year Typeclasses and their instances Course year 2016-2017 Typeclasses and their instances Doaitse Swierstra and Atze Dijkstra with extra s Utrecht University September 29, 2016 1. The basics 2 Overloading versus parametric polymorphism 1

More information

Introduction to Haskell

Introduction to Haskell Introduction to Haskell Matt Mullins Texas A&M Computing Society October 6, 2009 Matt Mullins (TACS) Introduction to Haskell October 6, 2009 1 / 39 Outline Introduction to Haskell Functional Programming

More information

Overview. Declarative Languages D7012E. Overloading. Overloading Polymorphism Subtyping

Overview. Declarative Languages D7012E. Overloading. Overloading Polymorphism Subtyping Overview Declarative Languages D7012E Lecture 4: The Haskell type system Fredrik Bengtsson / Johan Nordlander Overloading & polymorphism Type classes instances of type classes derived type classes Type

More information

Advanced features of Functional Programming (Haskell)

Advanced features of Functional Programming (Haskell) Advanced features of Functional Programming (Haskell) Polymorphism and overloading January 10, 2017 Monomorphic and polymorphic types A (data) type specifies a set of values. Examples: Bool: the type of

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

A Second Look At ML. Chapter Seven Modern Programming Languages, 2nd ed. 1

A Second Look At ML. Chapter Seven Modern Programming Languages, 2nd ed. 1 A Second Look At ML Chapter Seven Modern Programming Languages, 2nd ed. 1 Outline Patterns Local variable definitions A sorting example Chapter Seven Modern Programming Languages, 2nd ed. 2 Two Patterns

More information

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited

Topics Covered Thus Far. CMSC 330: Organization of Programming Languages. Language Features Covered Thus Far. Programming Languages Revisited CMSC 330: Organization of Programming Languages Type Systems, Names & Binding Topics Covered Thus Far Programming languages Syntax specification Regular expressions Context free grammars Implementation

More information

Exercises on ML. Programming Languages. Chanseok Oh

Exercises on ML. Programming Languages. Chanseok Oh Exercises on ML Programming Languages Chanseok Oh chanseok@cs.nyu.edu Dejected by an arcane type error? - foldr; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b - foldr (fn x=> fn y => fn z => (max

More information

JVM ByteCode Interpreter

JVM ByteCode Interpreter JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages Final Review Part I Dr. Hyunyoung Lee 1 Programming Language Characteristics Different approaches to describe computations, to instruct computing devices E.g., Imperative,

More information

Lecture 19: Functions, Types and Data Structures in Haskell

Lecture 19: Functions, Types and Data Structures in Haskell The University of North Carolina at Chapel Hill Spring 2002 Lecture 19: Functions, Types and Data Structures in Haskell Feb 25 1 Functions Functions are the most important kind of value in functional programming

More information

CSc 372 Comparative Programming Languages

CSc 372 Comparative Programming Languages CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Christian Collberg collberg+372@gmail.com Department of Computer Science University of Arizona Copyright c 2005 Christian Collberg

More information

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

CMSC 330: Organization of Programming Languages. Functional Programming with Lists CMSC 330: Organization of Programming Languages Functional Programming with Lists CMSC330 Spring 2018 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as

More information

CSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 8 : Haskell Function Examples. Department of Computer Science University of Arizona 1/43 CSc 372 Comparative Programming Languages 8 : Haskell Function Examples Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg Functions over Lists

More information

Programming in Haskell Aug-Nov 2015

Programming in Haskell Aug-Nov 2015 Programming in Haskell Aug-Nov 2015 LECTURE 14 OCTOBER 1, 2015 S P SURESH CHENNAI MATHEMATICAL INSTITUTE Enumerated data types The data keyword is used to define new types data Bool = False True data Day

More information

Haskell: From Basic to Advanced. Part 2 Type Classes, Laziness, IO, Modules

Haskell: From Basic to Advanced. Part 2 Type Classes, Laziness, IO, Modules Haskell: From Basic to Advanced Part 2 Type Classes, Laziness, IO, Modules Qualified types In the types schemes we have seen, the type variables were universally quantified, e.g. ++ :: [a] -> [a] -> [a]

More information

Chapter 3 Linear Structures: Lists

Chapter 3 Linear Structures: Lists Plan Chapter 3 Linear Structures: Lists 1. Lists... 3.2 2. Basic operations... 3.4 3. Constructors and pattern matching... 3.5 4. Polymorphism... 3.8 5. Simple operations on lists... 3.11 6. Application:

More information

The Typed Racket Guide

The Typed Racket Guide The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce

More information

CSE 505: Concepts of Programming Languages

CSE 505: Concepts of Programming Languages CSE 505: Concepts of Programming Languages Dan Grossman Fall 2003 Lecture 6 Lambda Calculus Dan Grossman CSE505 Fall 2003, Lecture 6 1 Where we are Done: Modeling mutation and local control-flow Proving

More information

CSE341: Programming Languages Lecture 7 First-Class Functions. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 7 First-Class Functions. Dan Grossman Winter 2013 CSE341: Programming Languages Lecture 7 First-Class Functions Dan Grossman Winter 2013 What is functional programming? Functional programming can mean a few different things: 1. Avoiding mutation in most/all

More information

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type.

OCaml. ML Flow. Complex types: Lists. Complex types: Lists. The PL for the discerning hacker. All elements must have same type. OCaml The PL for the discerning hacker. ML Flow Expressions (Syntax) Compile-time Static 1. Enter expression 2. ML infers a type Exec-time Dynamic Types 3. ML crunches expression down to a value 4. Value

More information

Datatype declarations

Datatype declarations Datatype declarations datatype suit = HEARTS DIAMONDS CLUBS SPADES datatype a list = nil (* copy me NOT! *) op :: of a * a list datatype a heap = EHEAP HEAP of a * a heap * a heap type suit val HEARTS

More information

02157 Functional Programming. Michael R. Ha. Lecture 2: Functions, Types and Lists. Michael R. Hansen

02157 Functional Programming. Michael R. Ha. Lecture 2: Functions, Types and Lists. Michael R. Hansen Lecture 2: Functions, Types and Lists nsen 1 DTU Compute, Technical University of Denmark Lecture 2: Functions, Types and Lists MRH 13/09/2018 Outline Functions as first-class citizens Types, polymorphism

More information

Programming Languages 3. Definition and Proof by Induction

Programming Languages 3. Definition and Proof by Induction Programming Languages 3. Definition and Proof by Induction Shin-Cheng Mu Oct. 22, 2015 Total Functional Programming The next few lectures concerns inductive definitions and proofs of datatypes and programs.

More information

Haskell Overview II (2A) Young Won Lim 8/9/16

Haskell Overview II (2A) Young Won Lim 8/9/16 (2A) Copyright (c) 2016 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 or any later version published

More information

Practical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.

Practical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction. Practical Practical An introduction to functional programming July 21, 2011 Contents Practical Practical is fun, and that s what it s all about! Even if seems strange to you at first, don t give up. Learning

More information

Functional Programming in Embedded System Design

Functional Programming in Embedded System Design Functional Programming in Embedded System Design Al Strelzoff CTO, E-TrolZ Lawrence, Mass. al.strelzoff@e-trolz.com 1/19/2006 Copyright E-TrolZ, Inc. 1 of 20 Hard Real Time Embedded Systems MUST: Be highly

More information

Typed Racket: Racket with Static Types

Typed Racket: Racket with Static Types Typed Racket: Racket with Static Types Version 5.0.2 Sam Tobin-Hochstadt November 6, 2010 Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type

More information

Topics Covered Thus Far CMSC 330: Organization of Programming Languages

Topics Covered Thus Far CMSC 330: Organization of Programming Languages Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free

More information

Haskell An Introduction

Haskell An Introduction Haskell An Introduction What is Haskell? General purpose Purely functional No function can have side-effects IO is done using special types Lazy Strongly typed Polymorphic types Concise and elegant A First

More information

Chapter 3 Linear Structures: Lists

Chapter 3 Linear Structures: Lists Plan Chapter 3 Linear Structures: Lists 1. Two constructors for lists... 3.2 2. Lists... 3.3 3. Basic operations... 3.5 4. Constructors and pattern matching... 3.6 5. Simple operations on lists... 3.9

More information

Background. CMSC 330: Organization of Programming Languages. Useful Information on OCaml language. Dialects of ML. ML (Meta Language) Standard ML

Background. CMSC 330: Organization of Programming Languages. Useful Information on OCaml language. Dialects of ML. ML (Meta Language) Standard ML CMSC 330: Organization of Programming Languages Functional Programming with OCaml 1 Background ML (Meta Language) Univ. of Edinburgh, 1973 Part of a theorem proving system LCF The Logic of Computable Functions

More information

Index. Cambridge University Press Functional Programming Using F# Michael R. Hansen and Hans Rischel. Index.

Index. Cambridge University Press Functional Programming Using F# Michael R. Hansen and Hans Rischel. Index. (),23 (*,3 ->,3,32 *,11 *),3.[...], 27, 186 //,3 ///,3 ::, 71, 80 :=, 182 ;, 179 ;;,1 @, 79, 80 @"...",26 >,38,35

More information

CS 360: Programming Languages Lecture 10: Introduction to Haskell

CS 360: Programming Languages Lecture 10: Introduction to Haskell CS 360: Programming Languages Lecture 10: Introduction to Haskell Geoffrey Mainland Drexel University Thursday, February 5, 2015 Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Introduction to the D programming language. Marc Fuentes - SED

Introduction to the D programming language. Marc Fuentes - SED Introduction to the D programming language Marc Fuentes - SED Why an another language? Fortran (90) is fast, has nice array features, but I/O and objects are not very powerful Why an another language?

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

Programming Languages and Compilers (CS 421)

Programming Languages and Compilers (CS 421) Programming Languages and Compilers (CS 421) #3: Closures, evaluation of function applications, order of evaluation #4: Evaluation and Application rules using symbolic rewriting Madhusudan Parthasarathy

More information

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

More information

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming

CMSC 330: Organization of Programming Languages. OCaml Imperative Programming CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory

More information

Background Operators (1E) Young Won Lim 7/7/18

Background Operators (1E) Young Won Lim 7/7/18 Background Operators (1E) Copyright (c) 2016-2018 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

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

Haskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G.

Haskell: Lists. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, Glenn G. Haskell: Lists CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Friday, February 24, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions

PROGRAMMING IN HASKELL. CS Chapter 6 - Recursive Functions PROGRAMMING IN HASKELL CS-205 - Chapter 6 - Recursive Functions 0 Introduction As we have seen, many functions can naturally be defined in terms of other functions. factorial :: Int Int factorial n product

More information

Outline. What is semantics? Denotational semantics. Semantics of naming. What is semantics? 2 / 21

Outline. What is semantics? Denotational semantics. Semantics of naming. What is semantics? 2 / 21 Semantics 1 / 21 Outline What is semantics? Denotational semantics Semantics of naming What is semantics? 2 / 21 What is the meaning of a program? Recall: aspects of a language syntax: the structure of

More information

To figure this out we need a more precise understanding of how ML works

To figure this out we need a more precise understanding of how ML works Announcements: What are the following numbers: 74/2/70/17 (2:30,2:30,3:35,7:30) PS2 due Thursday 9/20 11:59PM Guest lecture on Tuesday 9/25 o No RDZ office hours next Friday, I am on travel A brief comment

More information

Functional Programming. Overview. Topics. Recall λ-terms. Examples

Functional Programming. Overview. Topics. Recall λ-terms. Examples Topics Functional Programming Christian Sternagel Harald Zankl Evgeny Zuenko Department of Computer Science University of Innsbruck WS 2017/2018 abstract data types, algebraic data types, binary search

More information

The case for reactive objects

The case for reactive objects The case for reactive objects Johan Nordlander, Luleå Univ. och Technology (with Mark Jones, Andrew Black, Magnus Carlsson, Dick Kieburtz all (ex) OGI) Links meeting, April 6 1 Links killer apps Web services...

More information

CMSC 330: Organization of Programming Languages. Functional Programming with Lists

CMSC 330: Organization of Programming Languages. Functional Programming with Lists CMSC 330: Organization of Programming Languages Functional Programming with Lists 1 Lists in OCaml The basic data structure in OCaml Lists can be of arbitrary length Implemented as a linked data structure

More information

The Design of Core C++ (Notes)

The Design of Core C++ (Notes) The Design of Core C++ (Notes) Uday Reddy May 13, 1994 This note is to define a small formal language called Core C++ which reflects the essential structure of C++. As the name implies, the design only

More information

CSci 450: Org. of Programming Languages Overloading and Type Classes

CSci 450: Org. of Programming Languages Overloading and Type Classes CSci 450: Org. of Programming Languages Overloading and Type Classes H. Conrad Cunningham 27 October 2017 (after class) Contents 9 Overloading and Type Classes 1 9.1 Chapter Introduction.........................

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

CS 320: Concepts of Programming Languages

CS 320: Concepts of Programming Languages CS 320: Concepts of Programming Languages Wayne Snyder Computer Science Department Boston University Lecture 08: Type Classes o o Review: What is a type class? Basic Type Classes: Eq, Ord, Enum, Integral,

More information

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013 CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Winter 2013 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging

More information

F28PL1 Programming Languages. Lecture 11: Standard ML 1

F28PL1 Programming Languages. Lecture 11: Standard ML 1 F28PL1 Programming Languages Lecture 11: Standard ML 1 Imperative languages digital computers are concrete realisations of von Neumann machines stored program memory associations between addresses and

More information

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

More information

Monad Background (3A) Young Won Lim 11/18/17

Monad Background (3A) Young Won Lim 11/18/17 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 or any later version published

More information

Programming in Haskell Aug Nov 2015

Programming in Haskell Aug Nov 2015 Programming in Haskell Aug Nov 2015 LECTURE 23 NOVEMBER 12, 2015 S P SURESH CHENNAI MATHEMATICAL INSTITUTE Summary of IO Actions of type IO t1, t1 -> IO t2, t1 -> t2 -> IO t3 etc. As opposed to pure functions

More information

Functional Programming and Haskell

Functional Programming and Haskell Functional Programming and Haskell Tim Dawborn University of Sydney, Australia School of Information Technologies Tim Dawborn Functional Programming and Haskell 1/22 What are Programming Paradigms? A programming

More information

Haskell 101. (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza

Haskell 101. (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza Haskell 101 (Version 1 (July 18, 2012)) Juan Pedro Villa Isaza Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell 101: Contents Introduction Tutorial Homework Bibliography Haskell

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

More information

CS 440: Programming Languages and Translators, Spring 2019 Mon

CS 440: Programming Languages and Translators, Spring 2019 Mon Haskell, Part 4 CS 440: Programming Languages and Translators, Spring 2019 Mon 2019-01-28 More Haskell Review definition by cases Chapter 6: Higher-order functions Revisit currying map, filter Unnamed

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

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012

News. Programming Languages. Complex types: Lists. Recap: ML s Holy Trinity. CSE 130: Spring 2012 News CSE 130: Spring 2012 Programming Languages On webpage: Suggested HW #1 PA #1 (due next Fri 4/13) Lecture 2: A Crash Course in ML Please post questions to Piazza Ranjit Jhala UC San Diego Today: A

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java

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

SML A F unctional Functional Language Language Lecture 19

SML A F unctional Functional Language Language Lecture 19 SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list

More information

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University CS558 Programming Languages Winter 2018 Lecture 4a Andrew Tolmach Portland State University 1994-2018 Pragmatics of Large Values Real machines are very efficient at handling word-size chunks of data (e.g.

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 11 Functional Programming with Haskell 1/37 Programming Paradigms Unit 11 Functional Programming with Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE

More information

Solution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors

Solution sheet 1. Introduction. Exercise 1 - Types of values. Exercise 2 - Constructors Solution sheet 1 Introduction Please note that there can be other solutions than those listed in this document. This is a literate Haskell file which is available as PDF, as well as literate Haskell source

More information

Title: Recursion and Higher Order Functions

Title: Recursion and Higher Order Functions Programing Paradigms and Languages Title: Recursion and Higher Order Functions Students: Ysee Monir, Besart Vishesella Proffesor: Dr. Robert Kowalczyk In this presentation, we'll take a closer look at

More information

Advanced Functional Programming

Advanced Functional Programming Advanced Functional Programming Tim Sheard Portland State University Lecture 2: More about Type Classes Implementing Type Classes Higher Order Types Multi-parameter Type Classes Tim Sheard 1 Implementing

More information