Advanced Functional Programming
|
|
- Brett McCormick
- 7 years ago
- Views:
Transcription
1 Advanced Functional Programming Andres Löh Department of Information and Computing Sciences Utrecht University March 23, 2009
2 11. Type Classes 11-1
3 This lecture 11 What are type classes? Qualified types Evidence translation Extensions to the class system: Functional dependencies Associated types 11-2
4 11.1 Introduction to type classes 11-3
5 Type classes 11.1 One of the features that makes Haskell unique. Predicates on types (but not types themselves!). Provide ad-hoc polymorphism or overloading. Extensible or open. Haskell 98 only allows unary predicates, but already allows classes that range over types of different kinds (Eq and Show vs. Functor and Monad). Lots of extensions. Can be translated into polymorphic lambda calculus F ω. 11-4
6 Classes and instances 11.1 A class declaration defines a predicate. Each member of a class supports a certain set of methods. An instance declaration declares some types to be in the class, and provides evidence of that fact by providing implementations for the methods. Depending on the situation, we may ask different questions about a type and a class: Is the type a member of the class (yes or no)? Why/how is the type a member of the class (give me evidence, please)? Functions that use methods get class constraints that are like proof obligations. 11-5
7 Parametric vs. ad-hoc polymorphism 11.1 Parametric polymorphism swap :: (a, b) (b, a) swap (x, y) = (y, x) Unconstrained variables can be instantiated to all types. No assumptions about the type can be made in the definition of the function. The function works uniformly for all types. Ad-hoc polymorphism between :: (Ord a) a a a Bool between x y z = x y y z 11-6 Constrained variables can only be instantiated to members of the class. Since each instance is specific to a type, the behaviour can differ vastly depending on the type that is used.
8 Restrictions 11.1 The Haskell 98 design is rather restrictive: 11-7 only one type parameter per class only one instance per type superclasses are possible, but the class hierarchy must not be cyclic instances can only be declared for simple types, types of the form T a 1... a n (where T is not a type synonym and a 1,..., a n are type variables). instance or class contexts may only be of the form C a (where a is a type variable). function contexts can only be of the form C (a t 1... t n) (where a is a type variable and t 1,..., t n are types possibly containing variables).
9 Examples: Restrictions 11.1 instance Eq a Eq [a] instance Eq [a] Eq [a] -- illegal instance Eq Int Eq [Int] -- illegal instance Eq a Eq (a, Bool) -- illegal instance Eq [[a]] -- illegal instance Eq String -- illegal (Eq (f Int)) f Int f Int Bool (Eq [Int]) [Int] [Int] Bool -- illegal (Eq [a]) [a] [a] Bool -- illegal 11-8
10 Examples: Restrictions 11.1 instance Eq a Eq [a] instance Eq [a] Eq [a] instance Eq Int Eq [Int] instance Eq a Eq (a, Bool) instance Eq [[a]] instance Eq String (Eq (f Int)) f Int f Int Bool (Eq [Int]) [Int] [Int] Bool (Eq [a]) [a] [a] Bool -- illegal -- illegal -- illegal -- illegal -- illegal -- illegal -- illegal 11-8 The restrictions ensure that instance resolution is efficient and terminates, and that contexts are always reduced as much as possible.
11 11.2 Qualified types 11-9
12 Introduction 11.2 Types with contexts are also called qualified types. Mark Jones describes a Theory of Qualified Types, which is a framework of which the Haskell type class system is one specific instance. Qualified types can also be used to track other properties of types: presence or absence of labels in extensible records, subtyping conditions type equality constraints presence or absence of effects (see Hage, Holdermans, Middelkoop, ICFP 2007) 11-10
13 Example 11.2 Some contexts imply other contexts: Eq Int Eq [Int] Eq Bool, Ord Int Ord Int Eq Int The latter holds if we assume globally that an instance for Eq Int exists
14 Entailment 11.2 Entailment ( ) is a relation on two contexts. The following rules are given by the framework for qualified types: Q P P Q (mono) P Q Q R P R (trans) P Q ϕ is a substitution ϕ P ϕ Q (closure) 11-12
15 Type class entailment 11.2 Only these two rules are specific to the type class system: P π P Q class Q π P Q instance Q π P π (super) (inst) 11-13
16 Type class entailment 11.2 Only these two rules are specific to the type class system: P π P Q class Q π P Q instance Q π P π (super) (inst) Example class Eq a Ord a Ord a Eq a (super) The direction of the arrow is somewhat misleading. Not Eq a implies Ord a, but the other way around. Read: only if Eq a, we can define Ord a.
17 Validity of instances 11.2 Instance declarations must adhere to the class hierarchy: class Q π P ϕ Q instance P ϕ π is valid (valid) 11-14
18 Example: validity of instances 11.2 class (Eq a, Show a) Num a class Foo a Bar a class Foo a instance (Eq a, Show a) Foo [a] instance Num a Bar [a] 11-15
19 Example: validity of instances 11.2 class (Eq a, Show a) Num a class Foo a Bar a class Foo a instance (Eq a, Show a) Foo [a] instance Num a Bar [a]... c Foo a Bar a Num a Foo [a] (valid) i Num a Bar [a] is valid 11-15
20 Example: validity of instances 11.2 class (Eq a, Show a) Num a class Foo a Bar a class Foo a instance (Eq a, Show a) Foo [a] instance Num a Bar [a]... c Foo a Bar a Num a Foo [a] (valid) i Num a Bar [a] is valid c (Eq a, Show a) Num a (class) Num a (Eq a, Show a) i (Eq a, Show a) Foo [a] (inst) Num a Foo [a] 11-15
21 Type rules 11.2 Usually, type rules are of the form Γ e :: τ where Γ is an environment mapping identifiers to types, e is an expression, and t is a (possibly polymorphic) type
22 Type rules 11.2 Usually, type rules are of the form Γ e :: τ where Γ is an environment mapping identifiers to types, e is an expression, and t is a (possibly polymorphic) type. With qualified types, type rules are of the form P Γ e :: τ where P is a context representing (local) knowledge, and τ is a (possibly polymorphic, possibly overloaded) type
23 Context reduction 11.2 P Γ e :: π ρ P π P Γ e :: ρ (context-reduce) Haskell s type inference applies this rule where adequate: (= =) :: (Eq a) a a Bool hello :: String hello = = hello :: Bool Requires Eq String
24 Context introduction 11.2 P, π Γ e :: ρ P Γ e :: π ρ (context-intro) Haskell s type inference applies this rule when generalizing in a let or a toplevel declaration: between x y z = x y y z Inferred to be of type (Ord a) a a a Bool
25 A strange error 11.2 Using the following definition in a Haskell module results in a type error: maxlist = maximum 11-19
26 A strange error 11.2 Using the following definition in a Haskell module results in a type error: maxlist = maximum Monomorphism restriction A toplevel value without an explicit type signature is never overloaded
27 11.3 Evidence translation 11-20
28 Translating type classes 11.3 Type classes can be translated into a lambda calculus without type classes as follows: Each class declaration defines a record type (also called dictionary). Each instance declaration defines a function resulting in the dictionary type. Each method call selects the corresponding field from the dictionary. Context introduction corresponds to the abstraction of function arguments of dictionary type. Context reduction corresponds to the implicit construction and application of a dictionary argument
29 Example: evidence translation 11.3 class E a where e :: a a Bool instance E Int where e = (= =) instance E a E [a] where e [ ] [ ] = True e (x : xs) (y : ys) = e x y e xs ys e = False member :: E a a [a] Bool member [ ] = False member a (x : xs) = e a x member a xs duplicates :: E a [a] Bool duplicates [ ] = False duplicates (x : xs) = member x xs duplicates xs is = [[ ], [1], [2], [1, 2], [2, 1]] :: [[Int]] main = (duplicates is, duplicates (concat is)) 11-22
30 Example: evidence translation 11.3 class E a where e :: a a Bool instance E Int where e = (= =) instance E a E [a] where e [ ] [ ] = True e (x : xs) (y : ys) = e x y e xs ys e = False member :: E a a [a] Bool member [ ] = False member a (x : xs) = e a x member a xs duplicates :: E a [a] Bool duplicates [ ] = False duplicates (x : xs) = member x xs duplicates xs is = [[ ], [1], [2], [1, 2], [2, 1]] :: [[Int]] main = (duplicates is, duplicates (concat is)) data E a = E {e :: a a Bool} e Int :: E Int e Int = E {e = (= =)} e List :: E a E [a] e List e a = E {e = e } where e [ ] [ ] = True e (x : xs) (y : ys) = e e a x y e (e List e a) xs ys e = False member :: E a a [a] Bool member e a [ ] = False member e a a (x : xs) = e e a a x member e a a xs duplicates :: E a [a] Bool duplicates e a [ ] = False duplicates e a (x : xs) = member e a x xs duplicates e a xs is = [[ ], [1], [2], [1, 2], [2, 1]] :: [[Int]] main = (duplicates (e List e Int ) is, duplicates e Int (concat is)) 11-22
31 Dictionaries and superclasses 11.3 Dictionaries contain dictionaries of their superclasses: class Eq a Ord a data Ord a = Ord {eq :: Eq a, compare :: a a Ordering,...} 11-23
32 Dictionaries and polymorphic methods 11.3 class Functor f where fmap :: (a b) f a f b data Functor f = Functor {fmap :: a b.(a b) f a f b} The field fmap is a polymorphic field. Note that this is equivalent to the non-record data Functor f = Functor ( a b.(a b) f a f b) and different from the existential type data Functor f = a b.functor ((a b) f a f b) 11-24
33 Polymorphic fields vs. existential types 11.3 An existential type hides a specific type. A polymorphic field stores a polymorphic function. data Functor f = Functor ( a b.(a b) f a f b) data Functor f = a b.functor ((a b) f a f b) Functor :: ( a b.(a b) f a f b) Functor f Functor :: a b.((a b) f a f b) Functor f The constructor Functor takes a polymorphic function as an argument. The type of Functor is a so-called rank-2 polymorphic type. More in the next lecture
34 Type-directed translation 11.3 Evidence translation is a byproduct of type inference type rules can be augmented with translated terms. New form of rules: P Γ e e :: τ P Q e Modified rules: P Γ e e :: π ρ P π e π P Γ e e e π :: ρ (context-reduce) P, e π :: π Γ e e :: ρ P Γ e λe π e :: π ρ (context-intro)
35 Monomorphism restriction revisited 11.3 Question Why the monomorphism restriction? 11-27
36 Monomorphism restriction revisited 11.3 Question Why the monomorphism restriction? Answer To prevent unexpected inefficiency or loss of sharing
37 11.4 Defaulting 11-28
38 Defaulting of numeric classes 11.4 Main : t :: (Num t) t Defining x = 42 does not produce an error despite the monomorphism restriction
39 Defaulting of numeric classes 11.4 Main : t :: (Num t) t Defining x = 42 does not produce an error despite the monomorphism restriction. Haskell performs defaulting of Num constraints and chooses Integer in this case
40 GHCi defaulting 11.4 GHCi (not Haskell in general) also performs defaulting of other constraints than Num, to (): Main let maxlist = maximum Main : t maxlist maxlist :: [()] () Prevents annoying errors (show [ ]). Can lead to subtle mistakes (QuickCheck properties)
41 Ambiguity and coherence 11.4 Question What is the type of the following expression? show read 11-31
42 Ambiguity and coherence (contd.) 11.4 Such an expression is called ambiguous because it has a constraint mentioning a variable that does not occur in the rest of the type: (Show a, Read a) String String Choosing different types can lead to different behaviour. Ambiguous types are disallowed by Haskell if they cannot be defaulted. Ambiguity is a form of incoherence: if allowed, multiple translations of a program with possibly different behaviour are possible
43 Specialization 11.4 A specialization is a partially evaluated copy of an overloaded function trades code size for more efficiency. GHC provides a pragma for this purpose: between :: (Ord a) a a a Bool -# SPECIALISE between :: Char Char Char Bool #- causes between Char :: Char Char Char Bool between Char = between ord Char to be generated and used whenever between ord Char would normally be used Using a RULES pragma, one can even provide different implementations for specific types. (Why useful?)
44 11.5 Extensions 11-34
45 Extensions to the class system 11.5 Nearly all Haskell-98 restrictions to the class system can be lifted. The price: worse properties of the program, less predictability, worse error messages, partially unclear semantics and interactions, possible compiler bugs. Nevertheless, some extensions are useful, and it is important to explore the design space in order to find an optimum
46 Flexible instances and contexts 11.5 Lifts the restrictions on the shape of instances and contexts
47 Overlapping instances 11.5 Allows overlapping instance definitions such as instance Foo a Foo [a] instance Foo [Int] Two possibilities to construct Foo [Int] if instance Foo Int is also given. Both possibilities might lead to different behaviour (incoherence). The most specific instance is chosen
48 Overlapping instances and context reduction 11.5 What about? foo :: (Foo a) a a test x xs = foo (x : xs) 11-38
49 Overlapping instances and context reduction 11.5 What about? foo :: (Foo a) a a test x xs = foo (x : xs) Reducing the context of test from Foo [a] to Foo a prevents Foo [Int] from being selected! Delay? 11-38
50 Incoherent instances 11.5 If you let GHC infer a type for test in foo :: (Foo a) a a test x xs = foo (x : xs) you get (Foo [a]) a [a] [a], i.e., GHC tries to delay the decision
51 Incoherent instances (contd.) 11.5 If you specify test :: Foo a a [a] [a] you get an error unless you tell GHC to allow incoherent instances. Advice With incoherent instances, it is very hard to predict how the instances are built. Allow incoherent instances only if you make sure that different ways to construct an instance have the same behaviour! 11-40
52 Undecidable instances 11.5 With undecidable instances, it is no longer required that context reduction actually reduces the context. The type checker may loop: instance Foo [[a]] Foo [a] 11-41
53 Next lecture 11.5 Next lecture will be on GADTs (generalized algebraic data types). Read: Chung-chieh Shan. Sexy types in action. Next week: lectures will be given by José Pedro Magalhães. Second student talk session: Monday, April 6. Programming project deadline: Sunday, April 5 (strict)
Type Classes with Functional Dependencies
Appears in Proceedings of the 9th European Symposium on Programming, ESOP 2000, Berlin, Germany, March 2000, Springer-Verlag LNCS 1782. Type Classes with Functional Dependencies Mark P. Jones Department
More informationProgramming Language Rankings. Lecture 15: Type Inference, polymorphism & Type Classes. Top Combined. Tiobe Index. CSC 131! Fall, 2014!
Programming Language Rankings Lecture 15: Type Inference, polymorphism & Type Classes CSC 131 Fall, 2014 Kim Bruce Top Combined Tiobe Index 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)
More informationPOLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful
POLYTYPIC PROGRAMMING OR: Programming Language Theory is Helpful RALF HINZE Institute of Information and Computing Sciences Utrecht University Email: ralf@cs.uu.nl Homepage: http://www.cs.uu.nl/~ralf/
More informationAspect-Oriented Programming with Type Classes
Aspect-Oriented Programming with Type Classes Martin Sulzmann School of Computing, National University of Singapore S16 Level 5, 3 Science Drive 2, Singapore 117543 sulzmann@comp.nus.edu.sg Meng Wang School
More informationRegular Expressions and Automata using Haskell
Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions
More informationFirst Class Overloading via Insersection Type Parameters
First Class Overloading via Insersection Type Parameters Elton Cardoso 2, Carlos Camarão 1, and Lucilia Figueiredo 2 1 Universidade Federal de Minas Gerais, camarao@dcc.ufmg.br 2 Universidade Federal de
More informationIdris, a General Purpose Dependently Typed Programming Language: Design and Implementation
Under consideration for publication in J. Functional Programming 1 Idris, a General Purpose Dependently Typed Programming Language: Design and Implementation EDWIN BRADY School of Computer Science, University
More informationAdding GADTs to OCaml the direct approach
Adding GADTs to OCaml the direct approach Jacques Garrigue & Jacques Le Normand Nagoya University / LexiFi (Paris) https://sites.google.com/site/ocamlgadt/ Garrigue & Le Normand Adding GADTs to OCaml 1
More informationCSCI 253. Object Oriented Programming (OOP) Overview. George Blankenship 1. Object Oriented Design: Java Review OOP George Blankenship.
CSCI 253 Object Oriented Design: Java Review OOP George Blankenship George Blankenship 1 Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation Abstract Data Type (ADT) Implementation
More informationProgramming Fundamentals. Lesson 20 Sections
Programming Fundamentals Lesson 20 Sections Today, we will Study sections, in Haskell. Sections are another class of expressions that represent functions. A section is a binary operation where one of the
More informationPoor Man's Type Classes
Poor Man's Type Classes Martin Odersky EPFL IFIP WG2.8 workin roup meetin Boston, July 2006. 1 Goals Type classes are nice. A cottae industry of Haskell prorammers has sprun up around them. Should we add
More informationLecture 12: Abstract data types
Lecture 12: Abstract data types Algebras Abstract data types Encapsulation and information hiding Parameterization Algebras Definition Which kinds of data do we want to discuss? What can we do with it?
More informationDeterministic Discrete Modeling
Deterministic Discrete Modeling Formal Semantics of Firewalls in Isabelle/HOL Cornelius Diekmann, M.Sc. Dr. Heiko Niedermayer Prof. Dr.-Ing. Georg Carle Lehrstuhl für Netzarchitekturen und Netzdienste
More informationFormal Engineering for Industrial Software Development
Shaoying Liu Formal Engineering for Industrial Software Development Using the SOFL Method With 90 Figures and 30 Tables Springer Contents Introduction 1 1.1 Software Life Cycle... 2 1.2 The Problem 4 1.3
More informationOperator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example
Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics
More informationStatic vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer
Lecture 10: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
More informationChecking Access to Protected Members in the Java Virtual Machine
Checking Access to Protected Members in the Java Virtual Machine Alessandro Coglio Kestrel Institute 3260 Hillview Avenue, Palo Alto, CA 94304, USA Ph. +1-650-493-6871 Fax +1-650-424-1807 http://www.kestrel.edu/
More informationJava Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More informationGlossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
More informationOutsideIn(X) Modular type inference with local assumptions
Under consideration for publication in J. Functional Programming 1 OutsideIn(X) Modular type inference with local assumptions 11 April 2011 Dimitrios Vytiniotis Microsoft Research Simon Peyton Jones Microsoft
More informationProgramming and Reasoning with Algebraic Effects and Dependent Types
Programming and Reasoning with Algebraic Effects and Dependent Types Edwin C. Brady School of Computer Science, University of St Andrews, St Andrews, Scotland. Email: ecb10@st-andrews.ac.uk Abstract One
More informationThe Clean programming language. Group 25, Jingui Li, Daren Tuzi
The Clean programming language Group 25, Jingui Li, Daren Tuzi The Clean programming language Overview The Clean programming language first appeared in 1987 and is still being further developed. It was
More informationAdvanced Functional Programming (9) Domain Specific Embedded Languages
Advanced Functional Programming (9) Domain Specific Embedded Languages Advanced Functional Programming (9) Domain Specific Embedded Languages, Universiteit Utrecht http://www.cs.uu.nl/groups/st/ February
More informationThe Constrained-Monad Problem
The Constrained-Monad Problem (Corrected Version, 9th June 2014) Neil Sculthorpe ITTC The University of Kansas neil@ittc.ku.edu Jan Bracker Institut für Informatik Christian-Albrechts-Universität jbra@informatik.uni-kiel.de
More informationFun with Phantom Types
1 Fun with Phantom Types RALF HINZE Institut für Informatik III, Universität Bonn Römerstraße 164, 53117 Bonn, Germany Email: ralf@informatik.uni-bonn.de Homepage: http://www.informatik.uni-bonn.de/~ralf
More informationObject-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
More informationPractical Generic Programming with OCaml
Practical Generic Programming with OCaml Jeremy Yallop LFCS, University of Edinburgh ML Workshop 2007 Instead of this... type α tree = Node of α Branch of (α tree) (α tree) val show_tree : (α string) (α
More informationIntroducing Formal Methods. Software Engineering and Formal Methods
Introducing Formal Methods Formal Methods for Software Specification and Analysis: An Overview 1 Software Engineering and Formal Methods Every Software engineering methodology is based on a recommended
More informationPython 2 and 3 compatibility testing via optional run-time type checking
Python 2 and 3 compatibility testing via optional run-time type checking Raoul-Gabriel Urma Work carried out during a Google internship & PhD https://github.com/google/pytypedecl Python 2 vs. Python 3
More informationFunctional Programming. Functional Programming Languages. Chapter 14. Introduction
Functional Programming Languages Chapter 14 Introduction Functional programming paradigm History Features and concepts Examples: Lisp ML 1 2 Functional Programming Functional Programming Languages The
More informationCS-XXX: Graduate Programming Languages. Lecture 25 Multiple Inheritance and Interfaces. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 25 Multiple Inheritance and Interfaces Dan Grossman 2012 Multiple Inheritance Why not allow class C extends C1,C2,...{...} (and C C1 and C C2)? What everyone
More informationStorage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
More informationClass 16: Function Parameters and Polymorphism
Class 16: Function Parameters and Polymorphism SI 413 - Programming Languages and Implementation Dr. Daniel S. Roche United States Naval Academy Fall 2011 Roche (USNA) SI413 - Class 16 Fall 2011 1 / 15
More informationHow To Write A Generic Program In Hf2.2.1.2 (For All People)
Scrap your boilerplate with class: extensible generic functions Ralf Lämmel Microsoft Corp. ralfla@microsoft.com Simon Peyton Jones Microsoft Research simonpj@microsoft.com Abstract The Scrap your boilerplate
More informationThe Needle Programming Language
The Needle Programming Language The Needle Programming Language 1 What is Needle? Needle is an object-oriented functional programming language with a multimethod-based OO system, and a static type system
More informationGluing things together with Haskell. Neil Mitchell http://nmitchell.co.uk/
Gluing things together with Haskell Neil Mitchell http://nmitchell.co.uk/ Code Elegantly designed Build system Test harness Continuous integration Release bundling Installer generator Release distribution
More informationThis session. Abstract Data Types. Modularisation. Naming modules. Functional Programming and Reasoning
This session Functional Programming and Reasoning Dr Hans Georg Schaathun University of Surrey After this session, you should be able to use ADT-s in software design be able to implement simple ADT-s in
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationFunctional Programming
FP 2005 1.1 3 Functional Programming WOLFRAM KAHL kahl@mcmaster.ca Department of Computing and Software McMaster University FP 2005 1.2 4 What Kinds of Programming Languages are There? Imperative telling
More informationChapter 7: Functional Programming Languages
Chapter 7: Functional Programming Languages Aarne Ranta Slides for the book Implementing Programming Languages. An Introduction to Compilers and Interpreters, College Publications, 2012. Fun: a language
More informationTimber: A Programming Language for Real-Time Embedded Systems
Timber: A Programming Language for Real-Time Embedded Systems Andrew P. Black, Magnus Carlsson, Mark P. Jones, Richard Kieburtz and Johan Nordlander Department of Computer Science and Engineering OGI School
More information1 bool operator==(complex a, Complex b) { 2 return a.real()==b.real() 3 && a.imag()==b.imag(); 4 } 1 bool Complex::operator==(Complex b) {
Operators C and C++ 6. Operators Inheritance Virtual Alastair R. Beresford University of Cambridge Lent Term 2008 C++ allows the programmer to overload the built-in operators For example, a new test for
More information3 Pillars of Object-oriented Programming. Industrial Programming Systems Programming & Scripting. Extending the Example.
Industrial Programming Systems Programming & Scripting Lecture 12: C# Revision 3 Pillars of Object-oriented Programming Encapsulation: each class should be selfcontained to localise changes. Realised through
More informationLecture 18-19 Data Types and Types of a Language
Lecture 18-19 Data Types and Types of a Language April 29, 2014 Data Types and Types of a Language Data, Data Types and Types Type: Generalities Type Systems and Type Safety Type Equivalence, Coercion
More informationSources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationDetecting Pattern-Match Failures in Haskell. Neil Mitchell and Colin Runciman York University www.cs.york.ac.uk/~ndm/catch
Detecting Pattern-Match Failures in Haskell Neil Mitchell and Colin Runciman York University www.cs.york.ac.uk/~ndm/catch Does this code crash? risers [] = [] risers [x] = [[x]] risers (x:y:etc) = if x
More information11 November 2015. www.isbe.tue.nl. www.isbe.tue.nl
UML Class Diagrams 11 November 2015 UML Class Diagrams The class diagram provides a static structure of all the classes that exist within the system. Classes are arranged in hierarchies sharing common
More informationCross-platform Compilers for Functional Languages
Cross-platform Compilers for Functional Languages Research Paper Edwin Brady University of St Andrews, KY16 9SX, Scotland/UK, ecb10@st-andrews.ac.uk Abstract Modern software is often designed to run on
More informationEmbedding effect systems in Haskell
Embedding effect systems in Haskell Dominic Orchard Tomas Petricek Computer Laboratory, University of Cambridge firstname.lastname@cl.cam.ac.uk Abstract Monads are now an everyday tool in functional programming
More informationOn Understanding Types, Data Abstraction, and Polymorphism
1 Computing Surveys, Vol 17 n. 4, pp 471-522, December 1985 On Understanding Types, Data Abstraction, and Polymorphism Luca Cardelli AT&T Bell Laboratories, Murray Hill, NJ 07974 (current address: DEC
More informationThe Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3
The Relational Model Chapter 3 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase,
More informationParametric Domain-theoretic models of Linear Abadi & Plotkin Logic
Parametric Domain-theoretic models of Linear Abadi & Plotkin Logic Lars Birkedal Rasmus Ejlers Møgelberg Rasmus Lerchedahl Petersen IT University Technical Report Series TR-00-7 ISSN 600 600 February 00
More informationOn Understanding Types, Data Abstraction, and Polymorphism
On Understanding Types, Data Abstraction, and Polymorphism LUCA CARDELLI AT&T Bell Laboratories, Murray Hill, N. J. 07974 PETER WEGNER Department of Computer Science, Brown University, Providence, R. I.
More informationAnatomy of Programming Languages. William R. Cook
Anatomy of Programming Languages William R. Cook Copyright (C) 2013 2 Chapter 1 Preliminaries Preface What? This document is a series of notes about programming languages, originally written for students
More informationJava Interfaces. Recall: A List Interface. Another Java Interface Example. Interface Notes. Why an interface construct? Interfaces & Java Types
Interfaces & Java Types Lecture 10 CS211 Fall 2005 Java Interfaces So far, we have mostly talked about interfaces informally, in the English sense of the word An interface describes how a client interacts
More informationJournal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML
Journal of Functional Programming, volume 3 number 4, 1993. Dynamics in ML Xavier Leroy École Normale Supérieure Michel Mauny INRIA Rocquencourt Abstract Objects with dynamic types allow the integration
More informationSE 360 Advances in Software Development Object Oriented Development in Java. Polymorphism. Dr. Senem Kumova Metin
SE 360 Advances in Software Development Object Oriented Development in Java Polymorphism Dr. Senem Kumova Metin Modified lecture notes of Dr. Hüseyin Akcan Inheritance Object oriented programming languages
More informationTesting and Tracing Lazy Functional Programs using QuickCheck and Hat
Testing and Tracing Lazy Functional Programs using QuickCheck and Hat Koen Claessen 1, Colin Runciman 2, Olaf Chitil 2, John Hughes 1, and Malcolm Wallace 2 1 Chalmers University of Technology, Sweden
More informationComp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111
Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages Corky Cartwright Swarat Chaudhuri November 30, 20111 Overview I In OO languages, data values (except for designated non-oo
More informationProgramming and Reasoning with Side-Effects in IDRIS
Programming and Reasoning with Side-Effects in IDRIS Edwin Brady 19th October 2014 Contents 1 Introduction 3 1.1 Hello world............................................. 3 1.2 Outline................................................
More informationDescription of Class Mutation Mutation Operators for Java
Description of Class Mutation Mutation Operators for Java Yu-Seung Ma Electronics and Telecommunications Research Institute, Korea ysma@etri.re.kr Jeff Offutt Software Engineering George Mason University
More informationAP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationHarmless Advice. Daniel S Dantas Princeton University. with David Walker
Harmless Advice Daniel S Dantas Princeton University with David Walker Aspect Oriented Programming Aspect Oriented Programming IBM - 2004 IBM reports positive results in aspect-oriented programming experiments
More informationThe countdown problem
JFP 12 (6): 609 616, November 2002. c 2002 Cambridge University Press DOI: 10.1017/S0956796801004300 Printed in the United Kingdom 609 F U N C T I O N A L P E A R L The countdown problem GRAHAM HUTTON
More informationDebugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go
Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error
More informationMaar hoe moet het dan?
Maar hoe moet het dan? Onderzoek naar feedback in interactieve leeromgevingen bij de Faculteit Informatica Johan Jeuring Met bijdragen van Alex Gerdes, Bastiaan Heeren, Josje Lodder, Harrie Passier, Sylvia
More informationFUNDAMENTALS OF ARTIFICIAL INTELLIGENCE KNOWLEDGE REPRESENTATION AND NETWORKED SCHEMES
Riga Technical University Faculty of Computer Science and Information Technology Department of Systems Theory and Design FUNDAMENTALS OF ARTIFICIAL INTELLIGENCE Lecture 7 KNOWLEDGE REPRESENTATION AND NETWORKED
More informationSpecial Directions for this Test
1 Spring, 2013 Name: (Please do not write your id number!) COP 4020 Programming Languages I Test on Haskell and Functional Programming Special Directions for this Test This test has 7 questions and pages
More information13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
More information09336863931 : provid.ir
provid.ir 09336863931 : NET Architecture Core CSharp o Variable o Variable Scope o Type Inference o Namespaces o Preprocessor Directives Statements and Flow of Execution o If Statement o Switch Statement
More informationopalang - Rapid & Secure Web Development
opalang - Rapid & Secure Web Development Syllabus Brief History of Web Development Ideas and Goals The Language itself Community Reason for Development Services and Apps written in OPA Future of OPA OPA
More information3. Mathematical Induction
3. MATHEMATICAL INDUCTION 83 3. Mathematical Induction 3.1. First Principle of Mathematical Induction. Let P (n) be a predicate with domain of discourse (over) the natural numbers N = {0, 1,,...}. If (1)
More informationDenotational design with type class morphisms (extended version)
LambdaPix technical report 2009-01, March 2009 (minor revisions February 15, 2011) 1 Denotational design with type class morphisms (extended version) Conal Elliott LambdaPix conal@conal.net Abstract Type
More informationTaming Wildcards in Java s Type System
Taming Wildcards in Java s Type System Ross Tate University of California, San Diego rtate@cs.ucsd.edu Alan Leung University of California, San Diego aleung@cs.ucsd.edu Sorin Lerner University of California,
More informationML for the Working Programmer
ML for the Working Programmer 2nd edition Lawrence C. Paulson University of Cambridge CAMBRIDGE UNIVERSITY PRESS CONTENTS Preface to the Second Edition Preface xiii xv 1 Standard ML 1 Functional Programming
More informationComputing Concepts with Java Essentials
2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Computing Concepts with Java Essentials 3rd Edition Cay Horstmann
More informationThe Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1
The Relational Model Ramakrishnan&Gehrke, Chapter 3 CS4320 1 Why Study the Relational Model? Most widely used model. Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. Legacy systems in older models
More informationExtensible Effects An Alternative to Monad Transformers
Extensible Effects An Alternative to Monad Transformers Oleg Kiselyov Amr Sabry Cameron Swords Haskell Symposium 2013 Boston, MA Sep 23, 2013 We design and implement a library that solves the long-standing
More informationThe Habit Programming Language: The Revised Preliminary Report
The Habit Programming Language: The Revised Preliminary Report The High Assurance Systems Programming Project (Hasp) Department of Computer Science, Portland State University Portland, Oregon 97207, USA
More informationDesigning with Exceptions. CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219
Designing with Exceptions CSE219, Computer Science III Stony Brook University http://www.cs.stonybrook.edu/~cse219 Testing vs. Debugging Testing Coding Does the code work properly YES NO 2 Debugging Testing
More informationTeaching Statement Richard A. Eisenberg
Teaching Statement Richard A. Eisenberg Computer science strikes me as beautiful: how the rules of logic can be used to prove the undecidability of the halting problem, how the magic wand of induction
More informationJava Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
More informationCohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT - BCNS/05/FT - BIS/06/FT - BIS/05/FT - BSE/05/FT - BSE/04/PT-BSE/06/FT
BSc (Hons) in Computer Applications, BSc (Hons) Computer Science with Network Security, BSc (Hons) Business Information Systems & BSc (Hons) Software Engineering Cohort: BCA/07B/PT - BCA/06/PT - BCNS/06/FT
More informationAURA: A language with authorization and audit
AURA: A language with authorization and audit Steve Zdancewic University of Pennsylvania WG 2.8 2008 Security-oriented Languages Limin Jia, Karl Mazurak, Jeff Vaughan, Jianzhou Zhao Joey Schorr and Luke
More informationLecture Notes on Linear Search
Lecture Notes on Linear Search 15-122: Principles of Imperative Computation Frank Pfenning Lecture 5 January 29, 2013 1 Introduction One of the fundamental and recurring problems in computer science is
More informationUnboxed Polymorphic Objects for Functional Numerical Programming
Unboxed Polymorphic Objects for Functional Numerical Programming Christopher Rodrigues cirodrig@illinois.edu Wen-Mei Hwu w-hwu@illinois.edu IMPACT Technical Report IMPACT-12-02 University of Illinois at
More informationHow To Understand The Theory Of Computer Science
Theory of Computation Lecture Notes Abhijat Vichare August 2005 Contents 1 Introduction 2 What is Computation? 3 The λ Calculus 3.1 Conversions: 3.2 The calculus in use 3.3 Few Important Theorems 3.4 Worked
More informationIn order to understand Perl objects, you first need to understand references in Perl. See perlref for details.
NAME DESCRIPTION perlobj - Perl object reference This document provides a reference for Perl's object orientation features. If you're looking for an introduction to object-oriented programming in Perl,
More informationRalf Hinze Generic Programs and Proofs
Ralf Hinze Generic Programs and Proofs Bonn, 2000 Für Anja, Lisa und Florian Brief contents 1 Introduction 1 2 Background 15 3 Generic programs 53 4 Generic proofs 87 5 Examples 107 6 Generic Haskell 147
More informationIntroduction to type systems
Introduction to type systems p. 1/5 Introductory Course on Logic and Automata Theory Introduction to type systems Polyvios.Pratikakis@imag.fr Based on slides by Jeff Foster, UMD Introduction to type systems
More informationJAVA - INHERITANCE. extends is the keyword used to inherit the properties of a class. Below given is the syntax of extends keyword.
http://www.tutorialspoint.com/java/java_inheritance.htm JAVA - INHERITANCE Copyright tutorialspoint.com Inheritance can be defined as the process where one class acquires the properties methodsandfields
More informationDesign by Contract beyond class modelling
Design by Contract beyond class modelling Introduction Design by Contract (DbC) or Programming by Contract is an approach to designing software. It says that designers should define precise and verifiable
More informationHistory OOP languages Year Language 1967 Simula-67 1983 Smalltalk
History OOP languages Intro 1 Year Language reported dates vary for some languages... design Vs delievered 1957 Fortran High level programming language 1958 Lisp 1959 Cobol 1960 Algol Structured Programming
More informationFirst-Class Type Classes
First-Class Type Classes Matthieu Sozeau 1 and Nicolas Oury 2 1 Univ. Paris Sud, CNRS, Laboratoire LRI, UMR 8623, Orsay, F-91405 INRIA Saclay, ProVal, Parc Orsay Université, F-91893 sozeau@lri.fr 2 University
More informationMaking Standard ML a Practical Database Programming Language
Making Standard ML a Practical Database Programming Language Atsushi Ohori Katsuhiro Ueno Research Institute of Electrical Communication Tohoku University {ohori, katsu}@riec.tohoku.ac.jp Abstract Integrating
More informationPart VI. Object-relational Data Models
Part VI Overview Object-relational Database Models Concepts of Object-relational Database Models Object-relational Features in Oracle10g Object-relational Database Models Object-relational Database Models
More informationCloud Haskell. Distributed Programming with. Andres Löh. 14 June 2013, Big Tech Day 6 Copyright 2013 Well-Typed LLP. .Well-Typed
Distributed Programming with Cloud Haskell Andres Löh 14 June 2013, Big Tech Day 6 Copyright 2013 Well-Typed LLP Well-Typed The Haskell Consultants Overview Introduction Haskell Cloud Haskell Communication
More informationClasses and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:
In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our
More informationLecture 9. Semantic Analysis Scoping and Symbol Table
Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax
More information