Modules in UHC A proposal by: Tom Hofte & Eric Eijkelenboom.

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Transposing F to C Transposing F to C Andrew Kennedy & Don Syme Microsoft Research Cambridge, U.K.
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
Semantic Analysis and Symbol Tables
Type Inference David Walker COS 320. Criticisms of Typed Languages Types overly constrain functions & data polymorphism makes typed constructs useful.
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Cs776 (Prasad)L4Poly1 Polymorphic Type System. cs776 (Prasad)L4Poly2 Goals Allow expression of “for all types T” fun I x = x I : ’a -> ’a Allow expression.
ML Datatypes.1 Standard ML Data types. ML Datatypes.2 Concrete Datatypes  The datatype declaration creates new types  These are concrete data types,
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function F can return.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Elaboration or: Semantic Analysis Compiler Baojian Hua
Module Language. Module language The Standard ML module language comprises the mechanisms for structuring programs into separate units. –Program units.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Chapter TenModern Programming Languages1 Scope. Chapter TenModern Programming Languages2 Reusing Names n Scope is trivial if you have a unique name for.
Scope Chapter TenModern Programming Languages, 2nd ed.1.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
Programming in the large in ML Need mechanisms for –Modularization –Information hiding –Parametrization of interfaces While retaining type inference Modules:
Elaboration or: Semantic Analysis Compiler Baojian Hua
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
Introduction to ML Last time: Basics: integers, Booleans, tuples,... simple functions introduction to data types This time, we continue writing an evaluator.
Standard ML- Part II Compiler Baojian Hua
CSE 130 : Winter 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 7: Polymorphism.
Last Time Introduction Course Logistics Introduction to ML Base Types Tuples and Records Functions & Polymorphism See Harper ’ s Intro to ML.
Doaitse Swierstra Atze Dijkstra Doaitse Swierstra Atze Dijkstra Type Systems.
Type Checking  Legality checks  Operator determination  Overload resolution.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
© Kenneth C. Louden, Chapter 9 – Abstract Data Types and Modules Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
ML Datatypes.1 Standard ML Data types. ML Datatypes.2 Concrete Datatypes  The datatype declaration creates new types  These are concrete data types,
10/16/2015IT 3271 All about binding n Variables are bound (dynamically) to values n values must be stored somewhere in the memory. Memory Locations for.
Existential Types and Module Systems Xiaoheng Ji Department of Computing and Software March 19, 2004.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
Evolving the ML Module System Derek Dreyer Toyota Technological Institute at Chicago April 15, 2004.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
Chapter 9: Functional Programming in a Typed Language.
A Third Look At ML Chapter NineModern Programming Languages, 2nd ed.1.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Abstract Data Types and Modules Lecture 11 – ADT and Modules, Spring CSE3302 Programming.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
Error Example - 65/4; ! Toplevel input: ! 65/4; ! ^^ ! Type clash: expression of type ! int ! cannot have type ! real.
Advanced Functional Programming Tim Sheard 1 Lecture 17 Advanced Functional Programming Tim Sheard Oregon Graduate Institute of Science & Technology Lecture:
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
Cs776(Prasad)L112Modules1 Modules value : type : function :: structure : signature : functor.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
CMSC 330: Organization of Programming Languages Operational Semantics.
1 Objective Caml (Ocaml) Aaron Bloomfield CS 415 Fall 2005.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Programming Languages and Compilers (CS 421)
ML: a quasi-functional language with strong typing
Programming Languages Dan Grossman 2013
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
11.1 The Concept of Abstraction
slides created by Marty Stepp
FP Foundations, Scheme In Text: Chapter 14.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE-321 Programming Languages Introduction to Functional Programming
Java Programming Loops
Records and Type Classes
CSE 341 Lecture 11 b closures; scoping rules
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
11.1 The Concept of Abstraction
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Records and Type Classes
Presentation transcript:

Modules in UHC A proposal by: Tom Hofte & Eric Eijkelenboom

Contents Our exercise What are modules Modules in ML First-class modules as records Our syntax Well kinded and well-typed records Conclusion

Our goal Design a module system for the UHC Based on existing work No implementation; just design

What are modules? Packaging code Orderly organization of types and values Modules can be combined List module in Haskell Java package

What are modules? Core language and module language Good example: ML Haskell module language is weaker

Modules in ML Separate types and values that belong together Structures and signatures Structure contains values and types Signature classifies them

Modules in ML - Signatures Signature example signature INTMAP = sig type ‘a intmap val empty: ‘a intmap val find: ‘a intmap -> int -> ‘a val insert: int*’a -> ‘a intmap -> ‘a intmap end;

Modules in ML - Structures Structure example 1: Structure Intfn : INTMAP = struct type ‘a intmap = int -> ‘a fun empty i = “error” fun find f x = f x fun insert (a,b) f i = if i==a then b else f i end;

Modules in ML - Structures Structure example 2: Structure IntList : INTMAP = struct type ‘a intmap = [(Int, a)] fun empty i = [] fun find f x = … fun insert (a,b) f i = … end;

Modules in ML - Matching Implementation independent Signature can be seen as Java interface Structure should match signature Notation: s tructure : signature Or: structure :> signature

Modules in ML - Matching Transparent matching (‘:’) vs. opaque matching (‘:>’) Expression: IntFn.empty 5 Legal with transparent matching Illegal with opaque matching Correct: IntFn.insert IntFn.empty 5

Modules in ML - Functors Parameterized modules Function maps a structure to structure Functors

Modules in ML - Functors A signature: signature NewSig = sig newVal : `a intmap end; Create new structure using parameter: Functor NewStruct(IM : INTMAP) : NewSig struct val newVal = IM.extend IM.empty 5 end;

Modules in ML - Conclusion Structures can use each others types and values! This is exactly what modules are all about Idea: modules are implemented by using signatures, structures Functors are ordinary functions

How to do this in UHC? Use the ideas from ML UHC is written in Haskell Problem: Haskell has no signatures etc. Solution: implement modules as first- class objects

First-class modules as records We introduce record types (signatures) and records (structures) These record types are first-class citizens and can thus be used in functions We implement modules as records

Record types We would like to define a record type: record Set a f = { empty :: f a add :: a -> f a -> f a asList:: f a -> [a] }

Records And implement this record type with a record: intSet :: Set Int [] intSet = Set { empty = [] add = \(x::Int) xs -> … asList= id }

Our Syntax We have created a syntax that realizes modules in Haskell First, we introduce some additional syntax.

Record types and constructors Record type body declarations S ::= record A ∆ = {S’};S | l :: σ; S | ε Record constructor body declaration s ::= l = t | ε Addition to terms t ::= record A ∆ = {S} in t | P{s} | t.l|

Type classes Not in our syntax You can make more restriction Eg. Elements of a List module should be of the class EG You can do it with records. It works like functors in ML..

Types and type schemes Types: τ, ν ::= ν -> τ | A τ | a τ | τ ν Type schemes: σ ::=forall Δ. σ | exists Δ. σ | σ -> σ | τ Δ ::= a : κ, Δ | ε

More general types Types: quantifiers only on outer level: forall c. [c] -> Int Schemes: quantifiers also inside: f (g : forall c. [c] -> Int) = g[“hello”] + g[1, 2]

Well-kinded records k ::= * | k ->k Ω ::= a: k, Ω | A: k, Ω | record A, Ω | ε Ω τ : k Three different check rules kind, term and record type rules

Kind rules

Record type body rules

Term kind-check rules

What still to be done Nested records Abstract modules and existentials Kind and type inferencing Implement it for Atze in UHC

Conclusion Modules can be implemented as first- class citizens Using records Kind and type checking rules for records Still a lot of design work to do for a well working implementation for UHC