Runtime types
|
|
- Daniela Wilkinson
- 6 years ago
- Views:
Transcription
1 Runtime types LexiFi March 2017 Bloomberg/LexiFi workshop
2 OCaml and LexiFi LexiFi has been (happily) using OCaml since Strong involvment in the OCaml ecosystem: Member of the OCaml Consortium. Active role in core OCaml team since Major upstreamed contributions: native dynlink, first-class modules, extension points and PPX, advanced compiler warnings, etc. Open source packages (gen_js_api, dead_code_analyzer, ocaml-vdom, landmarks, csml, cmt_annot, ppx_tools). Funding community efforts (meetups, interns, OCaml consultants).
3 The LexiFi s OCaml compiler LexiFi has always maintained a local fork of the OCaml compiler. Redistributing this fork is made possible by the OCaml Consortium special license. Control of our entire implementation stack has proved extremely useful in several situations, e.g.: Cherry picking serious bug fixes ahead of OCaml releases. Early days of the Bbg/LexiFi project: tweaks for shipping IBox as a static library supportng older libc versions. Another customer struggles with long compilation times => Linear Scan allocator (now upstreamed). Better support for relocating the toolchain.
4 The LexiFi s OCaml compiler Ongoing effort to reduce the diff with upstream in order to reduce maintenance efforts: try to upstream local extensions, revert less useful ones. We usually synchronize with OCaml on official releases (once validated on our code base) + local cherry-picking of major bug fixes. Moving towards a full-fledged OCaml distribution and a better integration with the ecosystem (OPAM).
5 Local changes: syntax Alphanumeric infix operators. Date literals. Embedded module signatures.
6 Local changes: standard library A few useful additions to Set/Map, and optimized existing functions. List.map tail-recursive.
7 Local changes: type-checking Lazy local let-bindings. Structural subtyping of declared types. Strict dependency flag for more robust builds. Warnings on missed punning. Implicit subtyping (deprecated).
8 Local changes: backend More optimizations for lazy values. Embedded x86/amd64 machine code generator and COFF file generation.
9 Local changes: runtime types Key component for many of our internal libraries. Relatively small patch to the compiler. Collaboration with academic researchers for future upstream inclusion (unclear).
10 Type-driven generic programming in OCaml Type-driven generic programming can avoid a lot of boilerplate code: serialization (variants, JSON, XML), UI (e.g. BBUI), property-based testing, SQL mapping, interacting with dynamic languages (e.g. our template language). Unfortunately, the OCaml compiler erases types. 0, \000, false, None, [] have the same runtime representation.
11 Type-driven generic programming in OCaml Syntactic approach: generate code at compilation time (Camlp4/PPX). Runtime types: let the compiler generate values that represent types, provide libraries that allows writing generic operations based on these representations. Hybrid approach: PPX generates type witnesses, then manipulated by libraries. Disclaimer: runtime types not suited for performance-critical code (although a lot of care has been put to make type-safe inspection of type efficient).
12 Types of types An untyped low-level concrete representation of types: type stype = DT_int DT_string DT_list of stype... A layer of phantom typing to connect a static type and its dynamic representation: type 'a ttype (* internally = stype, but static guarantee that the representation is coherent with 'a *) Higher-level types to allow writing type-safe generic functions, such as Mlfi_xtypes.xtype.
13 Building a type representation explicitly let t = (ttype_of: int) in assert (stype_of_ttype t = DT_int)
14 Building a type representation with unification let t : int ttype = (ttype_of: _) in assert (stype_of_ttype t = DT_int)
15 Implicit parameters Missing labeled parameters of type ttype are automatically inserted: let f ~(t:int ttype) () = t let t = f () (* equivalent to: f ~t:(ttype_of: _) () and to: f ~t:(ttype_of: int ttype) () *)
16 Implicit parameters and polymorphic functions let f ~(t: 'a ttype) (_x : 'a) = t let d = f 42
17 Example: dynamics type dyn = Dyn: 'a ttype * 'a -> dyn let dyn ~(t : 'a ttype) (x: 'a) = Dyn (t, x)
18 Supported types: simple cases type stype = DT_int DT_float DT_string DT_date DT_tuple of stype list DT_list of stype DT_array of stype DT_option of stype DT_arrow of string * stype * stype...
19 Supported types type stype =... DT_abstract of string * stype list (* for types with a global path (e.g. (int, string) Foo.Bar.t *) DT_object of (string * stype) list (* only non-polymorphic methods, recursion not allowed *) DT_prop of (string * string) list * stype (* type t =... + [foo = "bar"; bar = "foo"] *) DT_var of int (* internal use *)
20 Supported types: data types type stype =... DT_node of node (* sum/record, allows recursion *) and node = { mutable rec_descr: node_descr; rec_name: string; rec_args: stype list; (*... some internal fields *) } and node_descr = DT_variant of variant_descr DT_record of record_descr
21 Data types and variant_descr = { variant_constrs: (string * props * variant_args) list; } and variant_args = C_tuple of stype list C_inline of stype (* a DT_record node *) and record_descr = { record_fields: (string * props * stype) list; record_repr: record_repr; }
22 Abstract types Only globally accessible abstract types can use the DT_abstract representation. For other abstract types (in functor s argument or result, or locally abstract types), one must export the ttype explicitly with the same name as the type: module F(X: sig end) : sig type foobar val foobar: foobar ttype end = struct type foobar = int let foobar = (ttype_of: foobar) end Current limitation: this only works for non-parametric abstract types.
23 Abstract type and functor module type S = sig type t val t: t ttype end module F(X: S) : S = struct type t = X.t list let t = (ttype_of: t) end
24 Locally abstract type let f (type t) (t : t ttype) = (ttype_of: t list)
25 Explicit binding DEPRECATED FORM! let f (t: 'a ttype) = let type : 'a = t in (ttype_of: 'a list)
26 Using runtime types: dynamic equality Dynamic witness of the equality of two types: module TypEq : sig type (_, _) t = Eq: ('a, 'a) t... end Checking equality: val ttypes_equality: 'a ttype -> 'b ttype -> ('a, 'b) TypEq.t option
27 Dynamics type dyn = Dyn: 'a ttype * 'a -> dyn let dyn ~t x = Dyn (t, x) let undyn (type t) ~(t : t ttype) (Dyn (s, x)) : t = match ttypes_equality t s with Some TypEq.Eq -> x None -> failwith "Invalid type" val dyn: t:'a ttype -> 'a -> dyn val undyn: t:'a ttype -> dyn -> 'a
28 Variants type variant = V_unit V_bool of bool V_int of int V_float of float V_string of string V_date of date V_tuple of variant list V_list of variant list V_array of variant array V_option of variant option V_record of (string * variant) list V_constructor of string * variant option V_variant of variant V_lazy of variant Lazy.t val variant: t:'a ttype -> 'a -> variant val of_variant: t:'a ttype -> variant -> 'a
29 stype <-> ttype val stype_of_ttype: 'a ttype -> stype type sttype = Ttype: 'a ttype -> sttype val sttype_of_stype: stype -> sttype
30 stype -> ttype: example let roundtrip s x = let (Ttype t) = sttype_of_stype s in variant ~t (of_variant ~t x) val roundtrip: stype -> variant -> variant
31 Type-safe deconstruction of ttype val xtype_of_ttype: 'a ttype -> 'a xtype type 'a xtype = Unit: unit xtype Bool: bool xtype Int: int xtype Float: float xtype String: string xtype...
32 Example: a generic value printer let print (type t) ~(t : t ttype) (x : t) = match xtype_of_ttype t with Unit -> (* t == unit *) print_string "()" Bool -> (* t == bool *) Printf.printf "%b" x Int -> (* t == int *) Printf.printf "%i" x Float -> (* t == float *) Printf.printf "%f" x String -> (* t == string *) Printf.printf "%S" x...
33 Type-safe deconstruction, built-in parametric types type 'a xtype =... Option: 'b ttype * 'b xtype Lazy.t -> 'b option xtype List: 'b ttype * 'b xtype Lazy.t -> 'b list xtype Array: 'b ttype * 'b xtype Lazy.t -> 'b array xtype Lazy: ('b ttype * 'b xtype Lazy.t) -> 'b Lazy.t xtype Prop: ((string * string) list * 'a ttype * 'a xtype Lazy.t) -> 'a xtype...
34 Example: a generic value printer, continued let rec print (type t) ~(t : t ttype) (x : t) = match xtype_of_ttype t with... List (s, _) -> (* t == 'b list; s : 'b ttype *) print_string "["; List.iter (fun y -> print ~t:s y; print_string ";") x; print_string "]" Does not work because polymorphic recursion must be made explicit: let rec print: type t. t:t ttype -> t -> unit = fun ~t x ->...
35 Sum types type 'a xtype = Sum: 'a Sum.t -> 'a xtype... module Sum: sig type 's t val constructors: 's t -> 's ecstr array val get_constructor_index: 's t -> 's -> int val lookup_constructor: 's t -> string -> int... end type 's ecstr = C: ('s, 't) C.t -> 's ecstr module C : sig type ('s, 't) t val ttype: (_, 't) t -> 't ttype val name: _ t -> string val project: ('s, 't) t -> 's -> 't option val inject:('s, 't) t -> 't -> 's... end
36 Sum type let rec print: type t. t:t ttype -> t -> unit = fun ~t x -> match xtype_of_ttype t with... Sum sum -> let (C cstr) = Sum.constructor sum x in Printf.printf "%s " (C.name cstr); let y = C.project_exn cstr x in print ~t:(c.ttype cstr) y
37 Record types type 'a xtype = Record: 'a Record.t -> 'a xtype... module Record = struct type 's t val fields: 's t -> 's efield list val build: 's t -> 's field_builder -> 's val make: 's t -> ('s record_builder -> unit) -> 's... end type 's efield = F: ('s, 't) F.t -> 's efield type 's field_builder = { mk: 't. ('s, 't) F.t -> 't } type 'a record_builder module F : sig type ('s, 't) t val ttype: (_, 't) t -> 't ttype val name: _ t -> string val get: ('s, 't) t -> 's -> 't val set: ('s, 't) t -> 's record_builder -> 't -> unit...
38 Record types let rec print: type t. t:t ttype -> t -> unit = fun ~t x -> match xtype_of_ttype t with... Record record -> print_string "{"; List.iter (fun (F field) -> Printf.printf "%s = " (F.name field); print ~t:(f.ttype field) (F.get field x); print_string ";" ) (Record.fields record); print_string "}"
39 Type-indexed tables Using monomorphic data structures indexed by stype. type 'a pr = ('a -> unit) type cprinter = Pr: 'a ttype * 'a pr -> cprinter let prs: cprinter_printer TypeHMap.t ref = ref TypeHMap.empty let register_printer ~t pr = prs := TypeHMap.add (stype_of_ttype t) (Pr (t, pr))!prs
40 Type-indexed tables Keep ttype around and check for dynamic equality: let assert_eq t1 t2 = match ttypes_equality t1 t2 with None -> assert false Some eq -> eq let find_printer (type t) (t : t ttype) : t pr option = let s = stype_of_ttype t in match TypeHMap.find_opt s!prs with Some (Pr (ty, pr)) -> (* pr: 'a pr; ty : 'a ttype *) let TypEq.Eq = assert_eq t ty in (* 'a == t *) Some pr None -> None
41 Type-indexed tables let rec print: type t. t:t ttype -> t -> unit = fun ~t x -> match find_printer t with Some pr -> pr x None -> match xtype_of_ttype t with...
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 informationCMSC 430 Introduction to Compilers. Fall Everything (else) you always wanted to know about OCaml (but were afraid to ask)
CMSC 430 Introduction to Compilers Fall 2015 Everything (else) you always wanted to know about OCaml (but were afraid to ask) OCaml You know it well from CMSC 330 All programming projects will be in OCaml
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 informationOCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java
OCaml Data : Organization of Programming Languages OCaml 4 Data Types & Modules So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists Ø One kind of data structure
More informationCMSC 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 informationHard deadline: 3/28/15 1:00pm. Using software development tools like source control. Understanding the environment model and type inference.
CS 3110 Spring 2015 Problem Set 3 Version 0 (last modified March 12, 2015) Soft deadline: 3/26/15 11:59pm Hard deadline: 3/28/15 1:00pm Overview In this assignment you will implement several functions
More informationSome Advanced ML Features
Some Advanced ML Features Mooly Sagiv Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming University of Washington: Dan Grossman ML is small Small number of powerful constructs
More informationTopics 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 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 informationCS Lectures 2-3. Introduction to OCaml. Polyvios Pratikakis
CS 490.40 Lectures 2-3 Introduction to OCaml Polyvios Pratikakis Based on slides by Jeff Foster History ML: Meta Language 1973, University of Edinburg Used to program search tactics in LCF theorem prover
More informationML Type Inference and Unification. Arlen Cox
ML Type Inference and Unification Arlen Cox Research Goals Easy to use, high performance parallel programming Primary contributions in backend and runtime Need a front end to target backend ML offers ease
More informationTopics 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 informationCMSC 330: Organization of Programming Languages. OCaml Data Types
CMSC 330: Organization of Programming Languages OCaml Data Types CMSC330 Spring 2018 1 OCaml Data So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists Ø One kind
More informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
More informationModules and Representation Invariants
Modules and Representation Invariants COS 326 Andrew W. Appel Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel In previous classes: Reasoning about individual OCaml expressions.
More informationMetaprogramming assignment 3
Metaprogramming assignment 3 Optimising embedded languages Due at noon on Thursday 29th November 2018 This exercise uses the BER MetaOCaml compiler, which you can install via opam. The end of this document
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages CMSC330 Fall 2017 OCaml Data Types CMSC330 Fall 2017 1 OCaml Data So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists
More informationData Types The ML Type System
7 Data Types 7.2.4 The ML Type System The following is an ML version of the tail-recursive Fibonacci function introduced Fibonacci function in ML in Section 6.6.1: EXAMPLE 7.96 1. fun fib (n) = 2. let
More informationWhy OCaml? Introduction to Objective Caml. Features of OCaml. Applications written in OCaml. Stefan Wehr
Motivation Introduction to Objective Caml Why OCaml? Stefan Wehr University of Freiburg. October 30, 2006 Motivation Simple Expressions and Types I/O and Compilation Resources Convenient encoding of tree
More informationIntroduction to Objective Caml
Introduction to Objective Caml Stefan Wehr University of Freiburg. October 30, 2006 Motivation Simple Expressions and Types Functions Simple Pattern Matching Compound Datatypes I/O and Compilation Resources
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 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 informationAbram Hindle Kitchener Waterloo Perl Monger October 19, 2006
OCaml Tutorial Abram Hindle Kitchener Waterloo Perl Monger http://kw.pm.org abez@abez.ca October 19, 2006 Abram Hindle 1 OCaml Functional Language Multiple paradigms: Imperative, Functional, Object Oriented
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 informationCS 11 Ocaml track: lecture 3
CS 11 Ocaml track: lecture 3 n Today: n A (large) variety of odds and ends n Imperative programming in Ocaml Equality/inequality operators n Two inequality operators: and!= n Two equality operators:
More informationType checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E
Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E if E then S while E do S S ; S Type checking of statements The purpose
More informationCIS 120 Midterm II November 8, Name (printed): Pennkey (login id):
CIS 120 Midterm II November 8, 2013 Name (printed): Pennkey (login id): My signature below certifies that I have complied with the University of Pennsylvania s Code of Academic Integrity in completing
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 March 2 nd, 2016 GUI: notifiers Transition to Java What is the type of xs? let r = {contents = 3} let xs = [(fun () -> r.contents
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 informationModular implicits for OCaml how to assert success. Gallium Seminar,
Modular implicits for OCaml how to assert success Jacques Garrigue Nagoya University Frédéric Bour Sponsored by Jane Street LLC Gallium Seminar, 14-03-2016 Garrigue & Bour Mdular implicits and success
More informationTopic 9: Type Checking
Recommended Exercises and Readings Topic 9: Type Checking From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6 and
More informationTopic 9: Type Checking
Topic 9: Type Checking 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6
More informationEPITA - Practical Programming 06 - Advanced Module Usage
More EPITA - Practical Programming 06 - Advanced Module Usage marwan.burelle@lse.epita.fr http://wiki-prog.infoprepa.epita.fr Outline More 1 Embedded Declaring Module Types 2 Data Structures And Code Safety
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 11 February 5, 2018 Review: Abstract types Finite Maps Homework 3 due tomorrow at 11:59:59pm Announcements (Homework 4 is due Tuesday, 2/20, and won
More informationL3 Programming September 19, OCaml Cheatsheet
OCaml Cheatsheet Note: this document comes from a previous course (by Sylvain Schimdt). The explanations of the OCaml syntax in this sheet are by no means intended to be complete or even sufficient; check
More informationCMSC 330: Organization of Programming Languages. OCaml Imperative Programming
CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Fall 2017 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory All
More informationA Short Introduction to OCaml
École Polytechnique INF549 A Short Introduction to OCaml Jean-Christophe Filliâtre September 11, 2018 Jean-Christophe Filliâtre A Short Introduction to OCaml INF549 1 / 102 overview lecture labs Jean-Christophe
More informationCMSC 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 informationDialects of ML. CMSC 330: Organization of Programming Languages. Dialects of ML (cont.) Features of ML. Functional Languages. Features of ML (cont.
CMSC 330: Organization of Programming Languages OCaml 1 Functional Programming Dialects of ML ML (Meta Language) Univ. of Edinburgh,1973 Part of a theorem proving system LCF The Logic of Computable Functions
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 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 informationReference Cells. Example
Introduction to Objective Caml Part 2 Stefan Wehr University of Freiburg. November 8, 2006 Remember: Variables are only names for values Can t asn to variables Solution: reference cells Constructor: ref
More informationMidterm 1. CMSC 430 Introduction to Compilers Spring Instructions Total 100. Name: March 14, 2012
Name: Midterm 1 CMSC 430 Introduction to Compilers Spring 2012 March 14, 2012 Instructions This exam contains 8 pages, including this one. Make sure you have all the pages. Write your name on the top of
More informationAn introduction to C++ template programming
An introduction to C++ template programming Hayo Thielecke University of Birmingham http://www.cs.bham.ac.uk/~hxt March 2015 Templates and parametric polymorphism Template parameters Member functions of
More informationInductive Definitions, continued
1 / 27 Inductive Definitions, continued Assia Mahboubi Jan 7th, 2016 2 / 27 Last lecture Introduction to Coq s inductive types: Introduction, elimination and computation rules; Twofold implementation :
More informationList Functions, and Higher-Order Functions
List Functions, and Higher-Order Functions Björn Lisper Dept. of Computer Science and Engineering Mälardalen University bjorn.lisper@mdh.se http://www.idt.mdh.se/ blr/ List Functions, and Higher-Order
More informationCIS 120 Midterm II November 8, 2013 SOLUTIONS
CIS 120 Midterm II November 8, 2013 SOLUTIONS 1 1. Facts about OCaml and Java (15 points) For each part, circle true or false. a. T F The.equals method in Java is roughly similar to OCaml s = operator.
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.
More informationThe reader is referred to the Objective Caml reference manual for a more detailed description of these features.
B Objective Caml 3.04 Independently of the development of Objective Caml, several extensions of the language appeared. One of these, named Olabl, was integrated with Objective Caml, starting with version
More informationHandout 2 August 25, 2008
CS 502: Compiling and Programming Systems Handout 2 August 25, 2008 Project The project you will implement will be a subset of Standard ML called Mini-ML. While Mini- ML shares strong syntactic and semantic
More informationVerifying the darcs patch code
Verifying the darcs patch code David Roundy Oregon State University November 20 2006 The subject of this talk Darcs a revision control system based on a formalism for manipulating changes, which allows
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from
More informationBackground. 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 informationPolymorphism. Lecture 19 CS 565 4/17/08
Polymorphism Lecture 19 CS 565 4/17/08 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We need to write
More informationCS 321 Programming Languages
CS 321 Programming Languages Intro to OCaml Lists Baris Aktemur Özyeğin University Last update made on Monday 2 nd October, 2017 at 19:27. Some of the contents here are taken from Elsa Gunter and Sam Kamin
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 informationCS 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 informationStatic Checking and Type Systems
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 The Structure of our Compiler Revisited Character stream Lexical
More informationINF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming
More informationModular Programming. Prof. Clarkson Fall Today s music: "Giorgio By Moroder" by Daft Punk
Modular Programming Prof. Clarkson Fall 2017 Today s music: "Giorgio By Moroder" by Daft Punk Moog modular synthesizer Based in Trumansburg, NY, 1953-1971 Game changing! picked up by the Beatles, the Rolling
More informationCS 11 Ocaml track: lecture 4. Today: modules
CS 11 Ocaml track: lecture 4 Today: modules The idea of modules What's the idea behind a "module"? Package up code so other people/programs can use it Control what parts of code are part of the interface
More informationFaculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology
Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False
More informationLecture 12: Data Types (and Some Leftover ML)
Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals
More informationAll the operations used in the expression are over integers. a takes a pair as argument. (a pair is also a tuple, or more specifically, a 2-tuple)
Weekly exercises in INF3110 week 41 6-10.10.2008 Exercise 1 Exercise 6.1 in Mitchell's book a) fun a(x,y) = x+2*y; val a = fn : int * int -> int All the operations used in the expression are over integers.
More informationn Closed book n You are allowed 5 cheat pages n Practice problems available in Course Materials n Check grades in Rainbow grades
Announcements Announcements n HW12: Transaction server n Due today at 2pm n You can use up to 2 late days, as always n Final Exam, December 17, 3-6pm, in DCC 308 and 318 n Closed book n You are allowed
More informationComparison of the Models of Organisation
16 Comparison of the Models of Organisation Chapters 14 and 15 respectively presented two models of application organisation: The functional/modular model and the model. These two models address, each
More informationCMSC 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 informationTuples. CMSC 330: Organization of Programming Languages. Examples With Tuples. Another Example
CMSC 330: Organization of Programming Languages OCaml 2 Higher Order Functions Tuples Constructed using (e1,..., en) Deconstructed using pattern matching Patterns involve parens and commas, e.g., (p1,p2,
More informationLists. Michael P. Fourman. February 2, 2010
Lists Michael P. Fourman February 2, 2010 1 Introduction The list is a fundamental datatype in most functional languages. ML is no exception; list is a built-in ML type constructor. However, to introduce
More informationFirst-class modules: hidden power and tantalizing promises
First-class modules: hidden power and tantalizing promises to GADTs and beyond Jeremy Yallop Applicative Ltd Oleg Kiselyov ML 2010 ACM SIGPLAN Workshop on ML September 26, 2010 Honestly there was no collusion
More informationAdam Chlipala University of California, Berkeley ICFP 2006
Modular Development of Certified Program Verifiers with a Proof Assistant Adam Chlipala University of California, Berkeley ICFP 2006 1 Who Watches the Watcher? Program Verifier Might want to ensure: Memory
More informationCSE341: Programming Languages Lecture 11 Type Inference. Dan Grossman Spring 2016
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Spring 2016 Type-checking (Static) type-checking can reject a program before it runs to prevent the possibility of some errors A feature
More informationLast time: generic programming
1/ 55 Last time: generic programming val (=) : { D: DATA } D. t D. t bool 2/ 55 This time: monads etc., continued >>= effect E 3/ 55 Recap: monads, bind and let An imperative program let id =! counter
More informationA Type is a Set of Values. Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values.
Types A Type is a Set of Values Consider the statement: Read Chapter 6 int n; Here we declare n to be a variable of type int; what we mean, n can take on any value from the set of all integer values. Also
More informationCSE 130, Fall 2005: Final Examination
CSE 130, Fall 2005: Final Examination Name: ID: Instructions, etc. 1. Write your answers in the space provided. 2. Wherever it says explain, write no more than three lines as explanation. The rest will
More informationWhidbey Enhancements to C# Jeff Vaughan MSBuild Team July 21, 2004
Whidbey Enhancements to C# Jeff Vaughan MSBuild Team July 21, 2004 Outline Practical Partial types Static classes Extern and the namespace alias qualifier Cool (and practical too) Generics Nullable Types
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationIntroduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming
Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics
More informationCSCI 2041: Functions, Mutation, and Arrays
CSCI 2041: Functions, Mutation, and Arrays Chris Kauffman Last Updated: Fri Sep 14 15:06:04 CDT 2018 1 Logistics OCaml System Manual: 1.1-1.3 Practical OCaml: Ch 1-2 OCaml System Manual: 25.2 (Pervasives
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 12 February 7, 2018 Partiality, Sequencing, Records Chapters 12, 13 Midterm 1 This Friday in class Review session Tonight, 6 7:30 PM DRLB A1 Announcements
More informationCMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics
Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End
More informationThe 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 informationD7020E. Robust and Energy-Efficient Real-Time Systems D7020E. Lecture 2: Components & the Timber language
Robust and Energy-Efficient Real-Time Systems Lecture 2: Components & the Timber language 1 1 Recall The dynamic evolution of a system... with offset asynchronous calls synchronous call T T blocked buffered
More informationD7020E. 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 informationTyped 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 informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationCOS 326 David Walker Princeton University
Functional Abstractions over Imperative Infrastructure and Lazy Evaluation COS 326 David Walker Princeton University slides copyright 2013-2015 David Walker and Andrew W. Appel permission granted to reuse
More informationCMSC 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 informationGradual Typing with Union and Intersection Types
Gradual Typing with Union and Intersection Types Giuseppe Castagna, Victor Lanvin ICFP 17 September 6, 2017 1 / 14 Outline 1 Motivating Example 2 Types and Subtyping 3 Function Types and Operators 4 Conclusion
More informationTyped Functional Programming In OCaml
Typed Functional Programming In OCaml Fabrice Le Fessant fabrice.le_fessant@{inria.fr,ocamlpro.com} November 6, 2013 Introducing Myself Full-time researcher at INRIA, programming languages and distributed
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 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 informationProgramming Languages Lecture 15: Recursive Types & Subtyping
CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)
More informationThe Typed Racket Reference
The Typed Racket Reference Version 5.1 Sam Tobin-Hochstadt February 14, 2011 #lang typed/racket/base #lang typed/racket 1 1 Type Reference Any Any Racket value. All other types are subtypes of Any. Nothing
More informationOutline. Introduction Concepts and terminology The case for static typing. Implementing a static type system Basic typing relations Adding context
Types 1 / 15 Outline Introduction Concepts and terminology The case for static typing Implementing a static type system Basic typing relations Adding context 2 / 15 Types and type errors Type: a set of
More informationOCaml. 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 informationCS3110 Spring 2016 Lecture 6: Modules
CS3110 Spring 2016 Lecture 6: Modules Modules are the O part of OCaml, influenced by objects in Java. We see the evolution: Classic ML, CambridgeML (CAML), and finally OCaml. David McQueen is writing the
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 3a Andrew Tolmach Portland State University 1994-2017 Binding, Scope, Storage Part of being a high-level language is letting the programmer name things: variables
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More information