Structural Typing for Structured Products
|
|
- Teresa Allison
- 5 years ago
- Views:
Transcription
1 Structural Typing for Structured Products Tim Williams Peter Marks 8th October 2014
2 Background The FPF Framework A standardized representation for describing payoffs A common suite of tools for trades which use this representation UI for providing trade parameters Mathematical document descriptions Pricing and risk management Barrier analysis Payments and other lifecycle events 1
3 FPF Lucid A DSL for describing exotic payoffs and strategies Control constructs based around schedules Produces abstract syntax allowing multiple interpretations Damas-Hindley-Milner type inference with constraints and polymorphic extensible row types 2
4 Lucid language Articulation driven design 3
5 Lucid language Articulation driven design Lucid type system Structural typing with Row Polymorphism 4
6 A simple numeric expression exp(x) 5
7 A simple numeric expression Monomorphic exp(x) exp : Double Double x : Double exp(x) : Double 6
8 A conditional expression c x y 7
9 A conditional expression c x y Polymorphic if _ then _ else _ : (Bool, a, a) a c : Bool x : a y : a if c then x else y : a Hindley-Milner type system 8
10 Overloaded numeric literal x
11 Overloaded numeric literal Subtyping x + 42 (+) : (Num, Num) Num 42 : Integer x : Num x + 42 : Num Subtyping constraints difficult to solve with full inference A complex extension to Hindley-Milner 10
12 Overloaded numeric literal x + 42 Polymorphic with type variable constraints (+) : Num a (a, a) a 42 : Num a a x : Num a a x + 42 : Num a a Any type variable can have a single constraint Unifier ensures constraints are met Simple extension to Hindley-Milner 11
13 A simple Lucid function capfloor(perf, cap, floor) max(floor, min(cap, perf)) 12
14 A simple Lucid function capfloor(perf, cap, floor) max(floor, min(cap, perf)) capfloor : Num a (a, a, a) a 13
15 A simple Lucid function capfloor(perf, cap, floor) max(floor, min(cap, perf)) capfloor : Num a (a, a, a) a capfloor(perf, 0, 1) Not obvious which argument when applying function 14
16 Grouping and labelling arguments capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) 15
17 Grouping and labelling arguments Records via Nominal typing capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) data Num a CapFloor a = CapFloor {cap : a, floor : a } capfloor : Num a (a, CapFloor a) a 16
18 Grouping and labelling arguments Records via Nominal typing capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) data Num a CapFloor a = CapFloor {cap : a, floor : a } capfloor : Num a (a, CapFloor a) a Don t want to force users to define data types 17
19 Grouping and labelling arguments Records via Nominal typing capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) data Num a CapFloor a = CapFloor {cap : a, floor : a } capfloor : Num a (a, CapFloor a) a Don t want to force users to define data types Don t want to force users to name a combination of fields 18
20 Grouping and labelling arguments Records via Nominal typing capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) data Num a CapFloor a = CapFloor {cap : a, floor : a } capfloor : Num a (a, CapFloor a) a Don t want to force users to define data types Don t want to force users to name a combination of fields Want to use the same fields in different data types 19
21 Grouping and labelling arguments capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) Structural record types capfloor : Num a (a, {cap : a, floor : a}) a 20
22 Grouping and labelling arguments capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) Structural record types capfloor : Num a (a, {cap : a, floor : a}) a capfloor(perf, {cap=0, floor=1}) capfloor(perf, {floor=1, cap=0}) Unifier is agnostic to field order 21
23 Grouping and labelling arguments Structural record types capfloor(perf, {cap, floor}) max(floor, min(cap, perf)) capfloor : Num a (a, {cap : a, floor : a}) a capfloor(perf, {cap=0, floor=1}) capfloor(perf, {floor=1, cap=0}) Unifier is agnostic to field order Note the above is still not quite what Lucid infers 22
24 Grouping and labelling arguments Structural record types capfloor(perf, r) max(floor, min(r.cap, r.perf)) capfloor : Num a (a, {cap : a, floor : a}) a capfloor(perf, {cap=0, floor=1}) capfloor(perf, {floor=1, cap=0}) Unifier is agnostic to field order Note the above is still not quite what Lucid infers Pattern matching is just syntactic sugar for field selection 23
25 Ignoring additional fields kgcf(perf, r) capfloor( r.part * (perf - r.strike), {cap = r.cap, floor = r.floor}) kgcf(perf, {part=1, strike=0.9, cap=0, floor=1.2}) 24
26 Ignoring additional fields kgcf(perf, r) capfloor(r.part * (perf - r.strike), r) kgcf(perf, {part=1, strike=0.9, cap=0, floor=1.2}) 25
27 Ignoring additional fields kgcf(perf, r) capfloor(r.part * (perf - r.strike), r) kgcf(perf, {part=1, strike=0.9, cap=0, floor=1.2}) Structural Record types capfloor : Num a (a, {cap : a, floor : a}) a kgcf : Num a (a, {part : a, strike : a, cap : a, floor : a}) a How do we allow a superset of fields to be passed to CapFloor? 26
28 Ignoring additional fields kgcf(perf, r) capfloor(r.part * (perf - r.strike), r) kgcf(perf, {part=1, strike=0.9, cap=0, floor=1.2}) Structural Record types capfloor : Num a (a, {cap : a, floor : a}) a kgcf : Num a (a, {part : a, strike : a, cap : a, floor : a}) a How do we allow a superset of fields to be passed to CapFloor? Subtyping would require a new type system and inference algorithm 27
29 Ignoring additional fields kgcf(perf, r) capfloor(r.part * (perf - r.strike), r) kgcf(perf, {part=1, strike=0.9, cap=0, floor=1.2}) Polymorphic extensible Records capfloor : Num a (a, {cap : a, floor : a r}) a kgcf : Num a (perf, {part : a, strike : a, cap : a, floor : a s}) a How do we allow a superset of fields to be passed to CapFloor? Subtyping would require a new type system and inference algorithm Can use parametric polymorphism by using a type variable to represent the remaining fields 28
30 Extending Records gcfbasket(perf, weights, r) kgcf( sumproduct(perfs, weights), {strike=1, part=r.part, cap=r.cap, floor=r.floor}) 29
31 Extending Records gcfbasket(perf, weights, r) kgcf(sumproduct(perfs, weights), {strike=1 r}) 30
32 Extending Records gcfbasket(perf, weights, r) kgcf(sumproduct(perfs, weights), {strike=1 r}) Polymorphic extensible Records kgcf : (Num a, s/part/strike/cap/floor) (a, {part : a, strike : a, cap : a, floor : a s}) a gcfbasket : (Num a, r/part/strike/cap/floor) (a, {part : a, cap : a, floor : a r}) a 31
33 Extending Records gcfbasket(perf, weights, r) kgcf(sumproduct(perfs, weights), {strike=1 r}) Polymorphic extensible Records kgcf : (Num a, s/part/strike/cap/floor) (a, {part : a, strike : a, cap : a, floor : a s}) a gcfbasket : (Num a, r/part/strike/cap/floor) (a, {part : a, cap : a, floor : a r}) a Type inference introduces lacks constraints on row variables 32
34 Row Polymorphism The idea of row (parametric) polymorphism is to use a type variable to represent any additional unknown fields: 1 gcfbasket : (Num a, r/part/strike/cap/floor) (a, {part : a, cap : a, floor : a r}) a 1 Row polymorphism can be implemented with or without the lacks predicate, depending on whether repeated (scoped) labels are desired. 33
35 Type constructors: Row kinds The empty row : ROW Extend a row type (one constructor per label): l : _ _ : ROW ROW 34
36 Type constructors: Records Construct a Record from a row type (gives product types, structurally): {_} : ROW 35
37 Primitive operations on Records Selection (_.l) : ar. (r/l) {l : a r} a Restriction (_ / l) : ar. (r/l) {l : a r} {r} Extension 2 {l=_ _} : ar. (r/l) (a, {r}) {l : a r} 2 Note that Record literals are desugared to record extension. 36
38 Enums and switching behaviour calcoffset(ccy) ccy == USD 3 ccy == JPY
39 Enums and switching behaviour calcoffset(ccy) ccy == USD 3 ccy == JPY 2 0 No way to limit the set of atoms that can be used 38
40 Enums and switching behaviour calcoffset(ccy) ccy == USD 3 ccy == JPY 2 0 No way to limit the set of atoms that can be used Forced to provide a default value in the else clause 39
41 Enums and switching behaviour calcoffset(ccy) ccy USD 3, JPY 2 40
42 Enums and switching behaviour Row polymorphism calcoffset(ccy) ccy USD 3, JPY 2 calcoffset : Num a USD, JPY a 41
43 Enums and switching behaviour Row polymorphism calcoffset(ccy) ccy USD 3, JPY 2 calcoffset : Num a USD, JPY a Enums can be implemented using row types with unit fields 42
44 Enums and switching behaviour Row polymorphism calcoffset(ccy) ccy USD 3, JPY 2 calcoffset : Num a USD, JPY a Enums can be implemented using row types with unit fields Note the top-level type is closed 43
45 Extending enums and reusing behaviour calcoffsetext(ccy) ccy GBP 3, otherwise c calcoffset(c) 44
46 Extending enums and reusing behaviour calcoffsetext(ccy) ccy GBP 3, otherwise c calcoffset(c) Polymorphic extensible cases calcoffset : Num a USD, JPY a calcoffsetext : Num a GBP, USD, JPY a c : USD, JPY 45
47 Extending enums and reusing behaviour calcoffsetext(ccy) ccy GBP 3, otherwise c calcoffset(c) Polymorphic extensible cases calcoffset : Num a USD, JPY a calcoffsetext : Num a GBP, USD, JPY a c : USD, JPY Composition of cases using delegation 46
48 Extending enums and reusing behaviour calcoffsetext(ccy) ccy GBP 3, otherwise c calcoffset(c) Polymorphic extensible cases calcoffset : Num a USD, JPY a calcoffsetext : Num a GBP, USD, JPY a c : USD, JPY Composition of cases using delegation Creates a new type containing a superset of fields 47
49 Extending enums and reusing behaviour calcoffsetext(ccy) ccy GBP 3, otherwise c calcoffset(c) Polymorphic extensible cases calcoffset : Num a USD, JPY a calcoffsetext : Num a GBP, USD, JPY a c : USD, JPY Composition of cases using delegation Creates a new type containing a superset of fields Flexibility similar to OOP subclassing, without giving up extensibility of functions 48
50 Limiting the behaviour of existing code calcoffset2(ccy) calcoffsetext( JPY ccy ) 49
51 Limiting the behaviour of existing code calcoffset2(ccy) calcoffsetext( JPY ccy ) Embedding calcoffsetext : Num a GBP, USD, JPY a calcoffset2 : Num a GBP, USD a 50
52 Limiting the behaviour of existing code calcoffset2(ccy) calcoffsetext( JPY ccy ) Embedding calcoffsetext : Num a GBP, USD, JPY a calcoffset2 : Num a GBP, USD a Embedding adds JPY to the type and restricts its values as possible input 51
53 Overriding existing behaviour calcoffsetext2(ccy) ccy override USD 4, otherwise c calcoffsetext(c) 52
54 Overriding existing behaviour Embedding calcoffsetext2(ccy) ccy override USD 4, otherwise c calcoffsetext(c) calcoffsetext : Num a GBP, USD, JPY a calcoffsetext2 : Num a GBP, USD, JPY a c : GBP, USD, JPY Override is syntactic sugar for embedding in the otherwise clause 53
55 Optional arguments calcbasket(perfs, aggregation, weights) aggregation Worst minarray(perfs), Best maxarray(perfs), Weighted sumproduct(perfs, weights) 54
56 Optional arguments calcbasket(perfs, aggregation, weights) aggregation Worst minarray(perfs), Best maxarray(perfs), Weighted sumproduct(perfs, weights) The weights argument is only used in the Weighted case 55
57 Optional arguments calcbasket(perfs, aggregation) aggregation Worst minarray(perfs), Best maxarray(perfs), Weighted(weights) sumproduct(perfs, weights) The weights argument is only used in the Weighted case 56
58 Optional arguments Variants calcbasket(perfs, aggregation) aggregation Worst minarray(perfs), Best maxarray(perfs), Weighted(weights) sumproduct(perfs, weights) The weights argument is only used in the Weighted case calcbasket : r/worst/best/weighted (double[n], Worst, Best, Weighted : double[n] r ) double Note that array sizes are also represented with a type variable 57
59 Type constructors: Records and Variants Construct a record from a row type (gives product types, structurally): {_} : ROW Construct a variant from a row type (gives sum types, structurally): _ : ROW 58
60 Primitive operations on Variants Injection (dual of selection) l=_ : ar. (r/l) a l : a r Embedding (dual of restriction) l _ : ar. (r/l) r l : a r Decomposition (dual of extension) l _?_:_ : abr. (r/l) l : a r a r 59
61 Primitive operations on Variants Injection (dual of selection) l=_ : ar. (r/l) a l : a r (_.l) : ar. (r/l) {l : a r} a Embedding (dual of restriction) l _ : ar. (r/l) r l : a r (_ / l) : ar. (r/l) {l : a r} {r} Decomposition (dual of extension) l _?_:_ : abr. (r/l) l : a r a r {l=_ _} : ar. (r/l) (a, {r}) {l : a r} 60
62 Decomposition (fused with a fold on the coproduct) 3 case _ of l _, otherwise _ : abr. (r/l) ( l : a r, a b, r b) b The empty alternative is used to close variants: emptyalt : b 3 Note that the case construct provides a notion of type refinement. 61
63 Tracking Effects paysomething(amt, sched, settl) sched Coupon amt settl 62
64 Tracking Effects paysomething(amt, sched, settl) sched Coupon amt settl Row-polymorphic effect types paysomething : (double, schedule, settlement) {payments} () Use row types to add an effect parameter to every function abe. a {e} b Only consider effects that are intrinsic to the language. Assume strict semantics, a function call inherits the effects from evaluation of its arguments. 63
65 Lacks constraint to restrict effects We want to prevent users from making payments in case alternatives, as conditional payments must be handled via other primitives: case _ of l _, otherwise _ : abre. (r/l, e/payments) ( l : a r, a {e} b, r b) b Note that we omit all unconstrained effect row variables. 64
66 An example Lucid function type autocallable : { asset : asset, fixedcouponamt : double, asianinschedule : schedule, asianoutschedule : schedule, couponschedule : schedule, autocallschedule : schedule, digitalcouponparams : { direction : <Up, Down, StrictlyUp, StrictlyDown>, level : double, amount : double }, perfcouponoption : { type : <Call, Put, Forward, Straddle, Const>, strike : double, part : double }, autocallparams : { direction : <Up, Down, StrictlyUp, StrictlyDown>, level : double, amount : double }, maturitydate : schedule, finalredemptionamt : double, kischedule : schedule, kibarrierparams : { direction : <Up, Down, StrictlyUp, StrictlyDown>, level : double }, kioption : { type : <Call, Put, Forward, Straddle, Const>, strike : double, part : double } } -> {payments, exit} () 65
67 Structural Typing Type equivalence determined by the type s actual structure, not by e.g. a name as in nominal typing. Research literature is almost completely concerned with structural type systems (TAPL 2002) 66
68 Benefits Permits sharing of constructors/labels amongst different types 67
69 Benefits Permits sharing of constructors/labels amongst different types Allows reuse of code across different (extended) types 68
70 Benefits Permits sharing of constructors/labels amongst different types Allows reuse of code across different (extended) types No requirement or dependency on type definitions or declarations, types can be fully inferred from their usage and are self-describing 69
71 Benefits Permits sharing of constructors/labels amongst different types Allows reuse of code across different (extended) types No requirement or dependency on type definitions or declarations, types can be fully inferred from their usage and are self-describing Creation of a Nominal type from a Structural type, just requires newtype or similar. The inverse is not so easy. 70
72 Benefits Permits sharing of constructors/labels amongst different types Allows reuse of code across different (extended) types No requirement or dependency on type definitions or declarations, types can be fully inferred from their usage and are self-describing Creation of a Nominal type from a Structural type, just requires newtype or similar. The inverse is not so easy. Combines the flexibility of unityping, with the safety of nominal typing 71
73 Benefits Permits sharing of constructors/labels amongst different types Allows reuse of code across different (extended) types No requirement or dependency on type definitions or declarations, types can be fully inferred from their usage and are self-describing Creation of a Nominal type from a Structural type, just requires newtype or similar. The inverse is not so easy. Combines the flexibility of unityping, with the safety of nominal typing Achieves the composition of data-types that we see in frameworks like Data types à la carte 72
74 Structural Typing in Haskell Haskell vanilla ADTs and Records are nominally typed We regularly see the tension of e.g. Tuples/HList versus Records. But Haskell essentially uses structural typing exclusively for functions: Haskell Java (Nominal) () -> IO () class Runnable { void run() } a -> a -> Ordering class Comparator { int compare(t, T) } a -> b class Function<? super T,? extends R> { R apply(t) } 73
75 An example type checker 74
76 References [1] B. R. Gaster, M. P. Jones, A Polymorphic Type System for Extensible Records and Variants, 1996 [2] J. Garrigue, Programming with Polymorphic Variants, 1998 [3] J. Garrigue, Code reuse through polymorphic variants, 2000 [4] D. Leijen, Extensible records with scoped labels, 2005 [5] D. Leijen, Koka : Programming with Row-polymorphic Effect Types,
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 informationCSCI-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 informationTypes and Type Inference
CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of
More informationTypes and Type Inference
Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion
More informationUser-Defined Algebraic Data Types
72 Static Semantics User-Defined Types User-Defined Algebraic Data Types An algebraic data type declaration has the general form: data cx T α 1... α k = K 1 τ 11... τ 1k1... K n τ n1... τ nkn introduces
More informationHaskell 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 informationType Processing by Constraint Reasoning
, Martin Sulzmann, Jeremy Wazny 8th November 2006 Chameleon Chameleon is Haskell-style language treats type problems using constraints gives expressive error messages has a programmable type system Developers:
More informationWhy Types Matter. Zheng Gao CREST, UCL
Why Types Matter Zheng Gao CREST, UCL Russell s Paradox Let R be the set of all sets that are not members of themselves. Is R a member of itself? If so, this contradicts with R s definition If not, by
More informationCSC324 Principles of Programming Languages
CSC324 Principles of Programming Languages http://mcs.utm.utoronto.ca/~324 November 21, 2018 Last Class Types terminology Haskell s type system Currying Defining types Value constructors Algebraic data
More informationOverview. 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 informationHarvard 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 informationIntroducing Wybe a language for everyone
Introducing Wybe a language for everyone Peter Schachte joint work with Matthew Giuca The University of Melbourne Department of Computing and Information Systems 4 December 2013 Peter Schachte (Melbourne)
More informationIntroduction 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 informationPolymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy
06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic
More informationShared Subtypes. Subtyping Recursive Parameterized Algebraic Data Types
Shared Subtypes Subtyping Recursive Parameterized Algebraic Data Types Ki Yung Ahn kya@cs.pdx.edu Tim Sheard sheard@cs.pdx.edu Department of Computer Science Maseeh College of Engineering & Computer Science
More informationCONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17
List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code
More informationLecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]
1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,
More informationHaske 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 informationSome instance messages and methods
Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationType Systems, Type Inference, and Polymorphism
6 Type Systems, Type Inference, and Polymorphism Programming involves a wide range of computational constructs, such as data structures, functions, objects, communication channels, and threads of control.
More informationAn 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 informationConcepts of Programming Languages
Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages
More informationCOURSE 2 DESIGN PATTERNS
COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract
More informationWhat are the characteristics of Object Oriented programming language?
What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationType-indexed functions in Generic Haskell
Type-indexed functions in Generic Haskell Johan Jeuring September 15, 2004 Introduction Today I will talk about: a Types of polymorphism. b Type-indexed functions. c Dependencies. Read about b, and c in
More informationCS152: 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 informationAccording 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 informationMore On Syntax Directed Translation
More On Syntax Directed Translation 1 Types of Attributes We have productions of the form: A X 1 X 2 X 3... X n with semantic rules of the form: b:= f(c 1, c 2, c 3,..., c n ) where b and the c s are attributes
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationTypes, Type Inference and Unification
Types, Type Inference and Unification Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Cornell CS 6110 Summary (Functional Programming) Lambda Calculus Basic ML Advanced ML: Modules, References,
More informationPierce Ch. 3, 8, 11, 15. Type Systems
Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using
More informationCS 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 informationSubclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented
Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and
More informationFUNCTIONAL AND LOGIC PROGRAMS
FUNCTIONAL AND LOGIC PROGRAMS Contents Language Specific Compilation Context Handling Identification Scope Overloading Imported Scope Type Checking Type table Type equivalence Coercions Casts and conversions
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationG 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 informationCS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE
CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate
More informationIntroduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples
Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the
More informationAdvanced 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 informationThe Hack programming language:
The Hack programming language: Types for PHP Andrew Kennedy Facebook Facebook s PHP Codebase 350,000 files >10,000,000 LoC (www.facebook.com & internally) 1000s of commits per day, 2 releases per day Anecdotally,
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and
More informationUsing Scala for building DSL s
Using Scala for building DSL s Abhijit Sharma Innovation Lab, BMC Software 1 What is a DSL? Domain Specific Language Appropriate abstraction level for domain - uses precise concepts and semantics of domain
More informationData Types. Every program uses data, either explicitly or implicitly to arrive at a result.
Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp-16/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 24! Type inference in ML / Haskell 1 Type Checking vs
More information2.4 Structuring programs
2.4 Structuring programs While theoretically a program could be written as one big expression, in reality we want some structure so that l The programmer has it easier to read the program l A compiler
More informationVariations on Variants
Variations on Variants J. Garrett Morris The University of Edinburgh Edinburgh, UK Garrett.Morris@ed.ac.uk Abstract Extensible variants improve the modularity and expressiveness of programming languages:
More informationA Short Summary of Javali
A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler
More informationIntroduce C# as Object Oriented programming language. Explain, tokens,
Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation
More informationC++ (Non for C Programmer) (BT307) 40 Hours
C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative
More informationType system. Type theory. Haskell type system. EDAN40: Functional Programming Types and Type Classes (revisited)
Type system EDAN40: Functional Programming Types and Type Classes (revisited) Jacek Malec Dept. of Computer Science, Lund University, Sweden April 3rd, 2017 In programming languages, a type system is a
More informationIntroduction 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 informationChapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.
Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures
More informationJava is an objet-oriented programming language providing features that support
Java Essentials CSCI 136: Spring 2018 Handout 2 February 2 Language Basics Java is an objet-oriented programming language providing features that support Data abstraction Code reuse Modular development
More informationReview. 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 informationCS558 Programming Languages
CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And
More informationInstantiation 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 informationChapter 11 Object and Object- Relational Databases
Chapter 11 Object and Object- Relational Databases Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11 Outline Overview of Object Database Concepts Object-Relational
More information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationProgramming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI
Programming Kotlin Familiarize yourself with all of Kotlin s features with this in-depth guide Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Copyright 2017 Packt Publishing First
More informationGeneric polymorphism on steroids
Generic polymorphism on steroids or How to Solve the Expression Problem with Polymorphic Variants Claudio Sacerdoti Coen Dipartimento di Informatica Scienza e Ingegneria
More informationBCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING
BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING Wednesady 23 rd March 2016 Afternoon Answer any FOUR questions out of SIX. All
More informationToday s lecture. CS 314 fall 01 C++ 1, page 1
Today s lecture Midterm Thursday, October 25, 6:10-7:30pm general information, conflicts Object oriented programming Abstract data types (ADT) Object oriented design C++ classes CS 314 fall 01 C++ 1, page
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationCOMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking
Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review
More informationBasics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011
Basics of Java: Expressions & Statements Nathaniel Osgood CMPT 858 February 15, 2011 Java as a Formal Language Java supports many constructs that serve different functions Class & Interface declarations
More informationArgument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.
Local Variable Initialization Unlike instance vars, local vars must be initialized before they can be used. Eg. void mymethod() { int foo = 42; int bar; bar = bar + 1; //compile error bar = 99; bar = bar
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationC++11/14 Rocks. Clang Edition. Alex Korban
C++11/14 Rocks Clang Edition Alex Korban 1 Contents Introduction 9 C++11 guiding principles... 9 Type Inference 11 auto... 11 Some things are still manual... 12 More than syntactic sugar... 12 Why else
More information(Not Quite) Minijava
(Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier
More informationarxiv: v1 [cs.pl] 1 May 2017
arxiv:1705.00556v1 [cs.pl] 1 May 2017 Mapping Objects to Persistent Predicates. José E. Zalacain Llanes Abstract The Logic Programming through Prolog has been widely used for supply persistence in many
More informationScala : an LLVM-targeted Scala compiler
Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................
More informationSEMANTIC ANALYSIS TYPES AND DECLARATIONS
SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether
More informationCompilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam
Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationSri Vidya College of Engineering & Technology
UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the
More informationl e t print_name r = p r i n t _ e n d l i n e ( Name : ^ r. name)
Chapter 8 Row polymorphism Consider the following code: type name_home = {name : s t r i n g ; home : s t r i n g } type name_mobile = {name : s t r i n g ; mobile : s t r i n g } l e t jane = {name =
More informationCloning Enums. Cloning and Enums BIU OOP
Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or
More informationChapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language
Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented
More informationBig Bang. Designing a Statically Typed Scripting Language. Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn
Big Bang Designing a Statically Typed Scripting Language Pottayil Harisanker Menon, Zachary Palmer, Scott F. Smith, Alexander Rozenshteyn The Johns Hopkins University June 11, 2012 Scripting Languages!
More information40 Behaviour Compatibility
40 Behaviour Compatibility [2] R. De Nicola, Extentional Equivalences for Transition Systems, Acta Informatica, vol. 24, pp. 21-237, 1987. [3] J. Gray, Notes on Data Base Operating Systems, in Operating
More informationLet Arguments Go First
Let Arguments Go First Ningning Xie and Bruno C. d. S. Oliveira The University of Hong Kong {nnxie,bruno}@cs.hku.hk Abstract. Bi-directional type checking has proved to be an extremely useful and versatile
More informationA brief introduction to C programming for Java programmers
A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically
More informationn 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 informationObject Oriented Issues in VDM++
Object Oriented Issues in VDM++ Nick Battle, Fujitsu UK (nick.battle@uk.fujitsu.com) Background VDMJ implemented VDM-SL first (started late 2007) Formally defined. Very few semantic problems VDM++ support
More informationSecond-generation: Assembly language. Figure 6.1 Generations of programming languages. Assembly Language Characteristics.
Chapter 6: Programming Languages Computer Science: An Overview Eleventh Edition by J. Glenn Brookshear Chapter 6: Programming Languages 6.1 Historical Perspective 6.2 Traditional Programming Concepts 6.3
More informationLecture Notes on Programming Languages
Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered
More informationA Small Permutation Group Engine by: Gregory Kip. COMS W4115 Programming Languages and Translators Prof. Stephen Edwards
µperm A Small Permutation Group Engine by: Gregory Kip COMS W4115 Programming Languages and Translators Prof. Stephen Edwards Abstract Given the abstract character of much of modern physics and mathematics,
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 05: Inheritance and Interfaces MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Inheritance and Interfaces 2 Introduction Inheritance and Class Hierarchy Polymorphism Abstract Classes
More informationAlex Kalicki, Alexandra Medway, Daniel Echikson, Lilly Wang
Alex Kalicki, Alexandra Medway, Daniel Echikson, Lilly Wang The Team Alexandra - The Manager Alex - The System Architect Danny - The Language Guru Lilly - The Tester The Process Branch, add a feature Make
More informationCS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?
CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look
More informationCopyright 2016 Ramez Elmasri and Shamkant B. Navathe
Chapter 12 Outline Overview of Object Database Concepts Object-Relational Features Object Database Extensions to SQL ODMG Object Model and the Object Definition Language ODL Object Database Conceptual
More informationObject Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia
Object Oriented Programming in Java Jaanus Pöial, PhD Tallinn, Estonia Motivation for Object Oriented Programming Decrease complexity (use layers of abstraction, interfaces, modularity,...) Reuse existing
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More information/ / JAVA TRAINING
www.tekclasses.com +91-8970005497/+91-7411642061 info@tekclasses.com / contact@tekclasses.com JAVA TRAINING If you are looking for JAVA Training, then Tek Classes is the right place to get the knowledge.
More information