SlideShare a Scribd company logo
1 of 51
Download to read offline
Module System of Standard ML
Jiten, Keheliya, Tobias
Tuesday 21st April, 2015
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 1 / 39
Outline
1 Modularity
2 Introduction to Standard ML
3 Modules in Standard ML
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 2 / 39
Outline
1 Modularity
2 Introduction to Standard ML
3 Modules in Standard ML
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 3 / 39
Why Modularity?
Writing large programs is difficult!
Lots of interdependencies
Changing code breaks other code
Concurrent development difficult
Maintenance is a nightmare.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 4 / 39
Why Modularity?
Writing large programs is difficult!
Lots of interdependencies
Changing code breaks other code
Concurrent development difficult
Maintenance is a nightmare.
The solution: Modularity
Implement program as independent modules
Hide information between modules to obscure implementation
details (abstraction)
Sharing: Interaction of program modules
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 4 / 39
How do programmers use modularity in C?
Write .h file (Header) and .c file (Source)
Header specifies variables and functions
Source is the full implementation
Compile library from both files and provide Header file as
interface.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 5 / 39
Outline
1 Modularity
2 Introduction to Standard ML
3 Modules in Standard ML
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 6 / 39
History of Standard ML
ML (stands for metalanguage)
Developed in Edinburgh in late ’70s
Designed by Michael J.C. Gordon, Robin Milner, and Christopher
P. Wadsworth
Standard ML (originated from ML)
Has a formal specification, given as typing rules and operational
semantics
The Definition of Standard ML (Revised) in 1997
Other siblings of the family: CAML, Caml Light, OCaml
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 7 / 39
Features of Standard ML
Higher-order functions
Interactive
Strongly Typed
Call-by-value
Polymorphism
Algebraic datatypes and pattern matching
Statically scoped
Type-safe exceptions
Modularity
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 8 / 39
Language Basics
Primitive Data Types: unit,bool,int,real,string
Function Expressions
val inc = fn x => x + 1
fun inc x = x + 1
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 9 / 39
Tuples, Records, Lists
Tuples
> val x = ("Prius", 1.0 / 2.0, false)
: string * real * bool
Records
> val dob = {day=21,month="July",year="1815"}
: {day:int, month:string, year:string}
Lists
> val price = [1.0,2.0,3.0];
> val price = 1.0 :: 2.0 :: 3.0 :: nil
val price = [1.0,2.0,3.0] : real list
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 10 / 39
Higher-order Functions
Functions can consume functions as arguments
fun applyTwice f x = f(f(x));
Functions can return functions
val add = fn x => fn y => x + y
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 11 / 39
Static Scoping
What is the output of this program?
val x = 2
fun f y = x+y
val x = 3
val z = f 4
Refers to the nearest lexically enclosing declaration!
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 12 / 39
Type Inference
Examples of type inference
fun ident (x) = x;
val ident = fn : ’a -> ’a
fun plus (x,y) = x+y;
val plus = fn : int * int -> int
fun new_if(A,B,C) = if A then B else C;
val new_if = fn : bool * ’a * ’a -> ’a
fun first (x,y) = x;
val first = fn : ’a * ’b -> ’a
’a standing for any type at all.
Function body makes no commitment to type of x at all.
Type inference produces the most general type, which may be
polymorphic.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 13 / 39
Pattern Matching
Wildcard Patterns
val (x,y,_) = (4,"May",1987);
val x = 4 : int
val y = "May" : string
Nested Patterns
val (a,b)::c::_ = [(3,true),(5,false),(9,false)];
val a = 3 : int
val b = true : bool
val c = (5,false) : int * bool
Function definition by cases
fun is_nil( nil ) = true
| is_nil(_::_) = false;
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 14 / 39
Recursive Types
datatype ’a tree = empty
| leaf of ’a
| node of ’a tree * ’a tree;
datatype ’a list = nil | :: of ’a * ’a list;
fun append(nil,l) = l
| append(hd::tl,l) = hd :: append(tl,l);
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 15 / 39
Recursive Typing
To type infinte data-structures (Lists, queues, trees, streams etc.)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 16 / 39
Recursive Typing
To type infinte data-structures (Lists, queues, trees, streams etc.)
Without Recursive typing:-
t ::“ nilT | consT t t | headT t | tailT t
v ::“ nilT | consT v v
T ::“ List T
Γ $ t1 : T1 Γ $ t2 : List T1
Γ $ consT1 t1 t2 : List T1
(T-cons)
Γ $ t1 : List T1
Γ $ headT1 t1 : T1
(T-head)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 16 / 39
Recursive Typing
To type infinte data-structures (Lists, queues, trees, streams etc.)
Without Recursive typing:-
t ::“ nilT | consT t t | headT t | tailT t
v ::“ nilT | consT v v
T ::“ List T
Γ $ t1 : T1 Γ $ t2 : List T1
Γ $ consT1 t1 t2 : List T1
(T-cons)
Γ $ t1 : List T1
Γ $ headT1 t1 : T1
(T-head)
Recursive typing:-
T ::“ X | rec X.T
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 16 / 39
Recursive Typing
To type infinte data-structures (Lists, queues, trees, streams etc.)
Without Recursive typing:-
t ::“ nilT | consT t t | headT t | tailT t
v ::“ nilT | consT v v
T ::“ List T
Γ $ t1 : T1 Γ $ t2 : List T1
Γ $ consT1 t1 t2 : List T1
(T-cons)
Γ $ t1 : List T1
Γ $ headT1 t1 : T1
(T-head)
Recursive typing:-
T ::“ X | rec X.T
IntList “ rec X. xnil : Unit, cons : tInt, Xuy
Nat “ rec X. xZero : Unit, succ : Xy
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 16 / 39
Recursive Typing...
t ::“ foldT t | unfoldT t
v ::“ foldT v
unfoldS pfoldT vq ÝÑ v(E-unfldfld)
U “ rec X.T1 Γ $ t1 : rU{XsT1
Γ $ foldU t1 : U
(T-fld)
U “ rec X.T1 Γ $ t1 : U
Γ $ unfoldU t1 : rU{XsT1
(T-unfld)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 17 / 39
Recursive Typing...
t ::“ foldT t | unfoldT t
v ::“ foldT v
unfoldS pfoldT vq ÝÑ v(E-unfldfld)
U “ rec X.T1 Γ $ t1 : rU{XsT1
Γ $ foldU t1 : U
(T-fld)
U “ rec X.T1 Γ $ t1 : U
Γ $ unfoldU t1 : rU{XsT1
(T-unfld)
nil “ foldrIntLists xnil “ unity
cons = λn : Int.λl : IntList.foldrIntLists xcons “ tn, luy
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 17 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
pλx : T11.t12q v2 rv2{xst12
pλX.t12q rT2s rT2{Xst12
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
pλx : T11.t12q v2 rv2{xst12
pλX.t12q rT2s rT2{Xst12
Γ, X $ t2 : T2
Γ $ λX.t2 : @X.T2
(T-Tabs)
Γ $ t1 : @X.T12
Γ $ t1 rT2s : rT2{XsT12
T-Tapp)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
pλx : T11.t12q v2 rv2{xst12
pλX.t12q rT2s rT2{Xst12
Γ, X $ t2 : T2
Γ $ λX.t2 : @X.T2
(T-Tabs)
Γ $ t1 : @X.T12
Γ $ t1 rT2s : rT2{XsT12
T-Tapp)
Example:-
@X. rec Y. xnil : Unit, cons : tX, Yuy
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
pλx : T11.t12q v2 rv2{xst12
pλX.t12q rT2s rT2{Xst12
Γ, X $ t2 : T2
Γ $ λX.t2 : @X.T2
(T-Tabs)
Γ $ t1 : @X.T12
Γ $ t1 rT2s : rT2{XsT12
T-Tapp)
Example:-
@X. rec Y. xnil : Unit, cons : tX, Yuy
Polymorphism in ML:-
Self-Application: Type of λx.x x?
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Parametric Polymorphism
t ::“ x | λx : T.t | t t | λX.t | t rTs
v ::“ λx : T.t | λX.t
T ::“ X | T Ñ T | @X.T
Γ ::“ Φ | Γ, x : T | Γ, X
pλx : T11.t12q v2 rv2{xst12
pλX.t12q rT2s rT2{Xst12
Γ, X $ t2 : T2
Γ $ λX.t2 : @X.T2
(T-Tabs)
Γ $ t1 : @X.T12
Γ $ t1 rT2s : rT2{XsT12
T-Tapp)
Example:-
@X. rec Y. xnil : Unit, cons : tX, Yuy
Polymorphism in ML:-
Self-Application: Type of λx.x x?
λx : @X.X Ñ X. x r@X.X Ñ Xs x : p@X.X Ñ Xq Ñ p@X.X Ñ Xq
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 18 / 39
Example: Stack
exception EmptyStack;
val empty = [];
fun push x r = x::r;
fun pop r = case r of
x::s => (x,s)
| [] => raise EmptyStack;
Type of push:
’a -> ’a list -> ’a list
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 19 / 39
Example: Stack
Type of push:
’a -> ’a list -> ’a list
This exposes the implementation datastructure (list)!
We want the view of the type to be abstract:
’a -> ’a stack -> ’a stack
ñ Need Standard ML’s abstract types in modules.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 20 / 39
Outline
1 Modularity
2 Introduction to Standard ML
3 Modules in Standard ML
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 21 / 39
Signatures
Signatures encode structural information
Specify a module’s value and function types
Provided explicitly by the programmer or discovered by type
inference
signature EQ =
sig
type elem
val eq: elem * elem -> bool
end;
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 22 / 39
Structures
structure is Standard ML’s Module
structure IntEq : EQ =
struct
type elem = int
val eq = (op =)
end;
Here, the signature is specified explicitly.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 23 / 39
All put together: Signature, Module and Access
signature EQ =
sig
type elem
val eq: elem * elem -> bool
end;
structure IntEq : EQ =
struct
type elem = int
val eq = (op =)
end;
IntEq.eq(3,4);
IntEq.eq(4,4);
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 24 / 39
Structures with explicit Signatures (1)
structure IntEq : EQ means that the structure’s inferred
signature is checked against the signature EQ
IntEq must provide at least what’s in EQ.
signature EQ =
sig
type elem
val eq: elem * elem -> bool
end;
structure IntEq : EQ =
struct
type elem = int
end;
> Error: unmatched value specification: eq
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 25 / 39
Structures with explicit Signatures (2)
We can make structure IntEq more powerful than EQ. But the
view is still restricted by the explicit signature EQ.
signature EQ =
sig
type elem
val eq: elem * elem -> bool
end;
structure IntEq : EQ =
struct
type elem = int
val eq = (op =)
val internalvalue = 1337
end;
IntEq.internalvalue;
> Error: unbound variable or constructor: internalvalue in
path IntEq.internalvalue
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 26 / 39
Opaque vs. Transparent Signatures (1)
Remember we could evaluate IntEq.eq(3,4);?
IntEq has signature EQ, which means IntEq.eq takes elem
variables as parameter – not integers!
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 27 / 39
Opaque vs. Transparent Signatures (1)
Remember we could evaluate IntEq.eq(3,4);?
IntEq has signature EQ, which means IntEq.eq takes elem
variables as parameter – not integers!
Well duh, calling with integers works, since IntEq.elem = int.
Signatures are transparent. We can make them opaque to strictly
restrict the view of IntEq to EQ.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 27 / 39
Opaque vs. Transparent Signatures (2)
structure IntEq :> EQ =
struct
type elem = int
val eq = (op =)
end;
IntEq.eq(3,4);
> Error: operator and operand don’t agree [literal]
operator domain: IntEq.elem * IntEq.elem
operand: int * int
in expression:
IntEq.eq (3,4)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 28 / 39
Stack Module
signature STACK =
sig
type ’a stack
val empty: ’a stack
val push: ’a -> ’a stack -> ’a stack
val pop: ’a stack -> ’a * ’a stack
end;
structure stack :> STACK =
struct
exception EmptyStack;
type ’a stack = ’a list;
val empty = [];
fun push x r = x::r;
fun pop r = case r of
x::s => (x,s)
| [] => raise EmptyStack;
end;
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 29 / 39
Stack Module
stack.push now has type:
’a -> ’a stack.stack -> ’a stack.stack.
Thanks to opaqueness, stack.push 3 [5]; is illegal.
Implementation protected. Yay!
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 30 / 39
Functors
A Functor takes a Structure as an argument and returns a
Structure.
They are defined using functor bindings at the top level (like
function definitions)
Limited to a single argument (Workaround: Several structures can
be packaged into one as substructures and then passed to a
functor)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 31 / 39
Functors: Example
functor F( P: EQ ) : EQ =
struct
type t = P.t * P.t
fun eq((x,y),(u,v)) = P.eq(x,u) andalso P.eq(y,v)
end;
structure IntEq : EQ =
struct
type t = int
val eq = (op =)
end;
structure IntTupleEq = F(IntEq);
IntTupleEq.eq((3,4),(3,4));
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 32 / 39
Functors with Submodules: Example
What if we want tuples of two different datatypes?
For instance tuples of Integers and Strings: eq((3,"a"),(3,"c"))
First, we introduce StringEq, similarly to IntEq:
structure StringEq : EQ =
struct
type t = string
val eq = (op =)
end;
Problem: functors only take a single structure as an argument. We
need to pass IntEq and StringEq!
Solution: Create a module containing both.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 33 / 39
Functors with Submodules: Example
signature TupleOfEQ =
sig
structure first : EQ
structure second : EQ
end;
functor F( P: TupleOfEQ ) : EQ =
struct
type t = P.first.t * P.second.t
fun eq((x,y),(u,v)) = P.first.eq(x,u) andalso P.second.eq(y,v)
end;
structure IntStringTuple : TupleOfEQ =
struct
structure first = IntEq
structure second = StringEq
end;
structure IntStringTupleCombined = F(IntStringTuple);
IntStringTupleCombined.eq((3,"a"),(3,"c"));
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 34 / 39
Sums and Products :-
Πx : A.B “
ą
t Bpxq | x P A u
Σx : A.B “  t Bpxq | x P A u
Elements of Πx : A.B fpaq “ ra{xsB.
Elements of Σx : A.B xa, by , a P A, b “ ra{xsB.
Strong sums:
sndppq : Bpfstppqq fstppq “ a.
Corresponds to the transparent signatures.
Weak sums:
Corresponds to the opaque ascription.
A form of existential type.
Transclucent sums:-
Optionally contain information about the representation of type.
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 35 / 39
Module system Calculus
Syntax:-
K ::“ Ω | K ñ K1
A ::“ α | Πx : A.A1 | D1, .., Dn | λα :: K | AA1 | V.b
D ::“ b Ź α :: K | b Ź α :: K “ A | y Ź x : A
M ::“ x | λx : A.M | MM1 | M : A | B1, .., Bn | M.y
B ::“ b Ź α “ A | y Ź x “ M
V ::“ x | λx : A.M | Bv1, .., Bvn | V.y
Bv ::“ b Ź α “ A | y Ź x “ V
Γ ::“ ˝ | Γ, α :: K | Γ, α :: K “ A | Γ, x : A
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 36 / 39
Module system Calculus
Syntax:-
K ::“ Ω | K ñ K1
A ::“ α | Πx : A.A1 | D1, .., Dn | λα :: K | AA1 | V.b
D ::“ b Ź α :: K | b Ź α :: K “ A | y Ź x : A
M ::“ x | λx : A.M | MM1 | M : A | B1, .., Bn | M.y
B ::“ b Ź α “ A | y Ź x “ M
V ::“ x | λx : A.M | Bv1, .., Bvn | V.y
Bv ::“ b Ź α “ A | y Ź x “ V
Γ ::“ ˝ | Γ, α :: K | Γ, α :: K “ A | Γ, x : A
Example:-
t elem Ź elem “ int, eq Ź eq “ λx : pelem ˚ elemq.pop “q, ival Ź ival “ 1337 u :
t elem Ź elem :: Ω “ int, eq Ź eq : pelem, elemq Ñ bool u
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 36 / 39
Module system Calculus..
Introduction and elimination rules:-
$ Γvalid @i P r1.ns. Γ, D1, .., Di´1 $ Bi : Di
Γ $ B1, .., Bn : D1, .., Dn
(TSUM)
Γ $ V : b Ź α :: K
Γ $ V.b :: K
(C-EXT-O)
Γ $ M : y Ź x : A
Γ $ M.y : A
(EXT-V)
Translucency:-
Γ $ V : b Ź α :: K “ A
Γ $ V.b “ A :: K
(ABBREV)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 37 / 39
Module system Calculus..
Value Rules:-
Γ $ V : b Ź α :: K, D1, .., Dn
Γ $ V : b Ź α :: K “ V.b, D1, .., Dn
(VALUE-O)
Γ $ V.y : A1 Γ $ V : y Ź x : A, D1, .., Dn
Γ $ V : y Ź x : A1, D1, .., Dn
(VALUE-V)
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 38 / 39
Summary and Outlook
ML has a powerful module system, using signatures, structures
and functors
Modules in ML are not part of the core language
Beyond ML Modules: Recursive modules, higher-order functors,
applicative functors
Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st
April, 2015 39 / 39

More Related Content

Viewers also liked

Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...
Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...
Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...Shane McIntosh
 
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...Tracing Software Build Processes to Uncover License Compliance Inconsistencie...
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...Shane McIntosh
 
Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionShane McIntosh
 
Icse2011 build maintenance
Icse2011 build maintenanceIcse2011 build maintenance
Icse2011 build maintenanceShane McIntosh
 
Tracing Software Build Processes to Uncover License Compliance Inconsistencies
Tracing Software Build Processes to Uncover License Compliance InconsistenciesTracing Software Build Processes to Uncover License Compliance Inconsistencies
Tracing Software Build Processes to Uncover License Compliance InconsistenciesShane McIntosh
 
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...Igor Wiese
 
Mining Co-Change Information to Understand when Build Changes are Necessary
Mining Co-Change Information to Understand when Build Changes are NecessaryMining Co-Change Information to Understand when Build Changes are Necessary
Mining Co-Change Information to Understand when Build Changes are NecessaryShane McIntosh
 
The Impact of Code Review Coverage and Participation on Software Quality
The Impact of Code Review Coverage and Participation on Software QualityThe Impact of Code Review Coverage and Participation on Software Quality
The Impact of Code Review Coverage and Participation on Software QualityShane McIntosh
 
O que é BIG DATA e como pode influenciar nossas vidas
O que é BIG DATA e como pode influenciar nossas vidasO que é BIG DATA e como pode influenciar nossas vidas
O que é BIG DATA e como pode influenciar nossas vidasElaine Naomi
 

Viewers also liked (13)

Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...
Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...
Collecting and Leveraging a Benchmark of Build System Clones to Aid in Qualit...
 
Buildtechs
BuildtechsBuildtechs
Buildtechs
 
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...Tracing Software Build Processes to Uncover License Compliance Inconsistencie...
Tracing Software Build Processes to Uncover License Compliance Inconsistencie...
 
Cross-Project Build Co-change Prediction
Cross-Project Build Co-change PredictionCross-Project Build Co-change Prediction
Cross-Project Build Co-change Prediction
 
Icse2011 build maintenance
Icse2011 build maintenanceIcse2011 build maintenance
Icse2011 build maintenance
 
Tracing Software Build Processes to Uncover License Compliance Inconsistencies
Tracing Software Build Processes to Uncover License Compliance InconsistenciesTracing Software Build Processes to Uncover License Compliance Inconsistencies
Tracing Software Build Processes to Uncover License Compliance Inconsistencies
 
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...
USING STRUCTURAL HOLES METRICS FROM COMMUNICATION NETWORKS TO PREDICT CHANGE ...
 
ICSE2011_SRC
ICSE2011_SRC ICSE2011_SRC
ICSE2011_SRC
 
Mining Co-Change Information to Understand when Build Changes are Necessary
Mining Co-Change Information to Understand when Build Changes are NecessaryMining Co-Change Information to Understand when Build Changes are Necessary
Mining Co-Change Information to Understand when Build Changes are Necessary
 
The Impact of Code Review Coverage and Participation on Software Quality
The Impact of Code Review Coverage and Participation on Software QualityThe Impact of Code Review Coverage and Participation on Software Quality
The Impact of Code Review Coverage and Participation on Software Quality
 
Qt Apresentação
Qt ApresentaçãoQt Apresentação
Qt Apresentação
 
Sonar Metrics
Sonar MetricsSonar Metrics
Sonar Metrics
 
O que é BIG DATA e como pode influenciar nossas vidas
O que é BIG DATA e como pode influenciar nossas vidasO que é BIG DATA e como pode influenciar nossas vidas
O que é BIG DATA e como pode influenciar nossas vidas
 

Similar to Module System in Standard ML

C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template LibraryIlio Catallo
 
Information filtering networks
Information filtering networksInformation filtering networks
Information filtering networksTomaso Aste
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New GameJohn De Goes
 
A Transformational Approach to Resource Analysis with Typed-Norms
A Transformational Approach to Resource Analysis  with Typed-NormsA Transformational Approach to Resource Analysis  with Typed-Norms
A Transformational Approach to Resource Analysis with Typed-NormsFacultad de Informática UCM
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowLightbend
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in JuliaJiahao Chen
 
My data are incomplete and noisy: Information-reduction statistical methods f...
My data are incomplete and noisy: Information-reduction statistical methods f...My data are incomplete and noisy: Information-reduction statistical methods f...
My data are incomplete and noisy: Information-reduction statistical methods f...Umberto Picchini
 
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...Computer Generated Items, Within-Template Variation, and the Impact on the Pa...
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...Quinn Lathrop
 
20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrisonComputer Science Club
 
Probabilistic Modelling with Information Filtering Networks
Probabilistic Modelling with Information Filtering NetworksProbabilistic Modelling with Information Filtering Networks
Probabilistic Modelling with Information Filtering NetworksTomaso Aste
 
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Peter Breuer
 
Write down the four (4) nonlinear regression models covered in class,.pdf
Write down the four (4) nonlinear regression models covered in class,.pdfWrite down the four (4) nonlinear regression models covered in class,.pdf
Write down the four (4) nonlinear regression models covered in class,.pdfjyothimuppasani1
 
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Dmitrii Ignatov
 
A walk through the intersection between machine learning and mechanistic mode...
A walk through the intersection between machine learning and mechanistic mode...A walk through the intersection between machine learning and mechanistic mode...
A walk through the intersection between machine learning and mechanistic mode...JuanPabloCarbajal3
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 

Similar to Module System in Standard ML (20)

Q
QQ
Q
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Information filtering networks
Information filtering networksInformation filtering networks
Information filtering networks
 
Scalaz 8: A Whole New Game
Scalaz 8: A Whole New GameScalaz 8: A Whole New Game
Scalaz 8: A Whole New Game
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
A Transformational Approach to Resource Analysis with Typed-Norms
A Transformational Approach to Resource Analysis  with Typed-NormsA Transformational Approach to Resource Analysis  with Typed-Norms
A Transformational Approach to Resource Analysis with Typed-Norms
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To KnowScala 3 Is Coming: Martin Odersky Shares What To Know
Scala 3 Is Coming: Martin Odersky Shares What To Know
 
What's next in Julia
What's next in JuliaWhat's next in Julia
What's next in Julia
 
My data are incomplete and noisy: Information-reduction statistical methods f...
My data are incomplete and noisy: Information-reduction statistical methods f...My data are incomplete and noisy: Information-reduction statistical methods f...
My data are incomplete and noisy: Information-reduction statistical methods f...
 
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...Computer Generated Items, Within-Template Variation, and the Impact on the Pa...
Computer Generated Items, Within-Template Variation, and the Impact on the Pa...
 
20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison
 
Probabilistic Modelling with Information Filtering Networks
Probabilistic Modelling with Information Filtering NetworksProbabilistic Modelling with Information Filtering Networks
Probabilistic Modelling with Information Filtering Networks
 
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...Tutorial: Formal Methods for Hardware Verification - Overview and Application...
Tutorial: Formal Methods for Hardware Verification - Overview and Application...
 
Classification
ClassificationClassification
Classification
 
MUMS: Bayesian, Fiducial, and Frequentist Conference - Multidimensional Monot...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Multidimensional Monot...MUMS: Bayesian, Fiducial, and Frequentist Conference - Multidimensional Monot...
MUMS: Bayesian, Fiducial, and Frequentist Conference - Multidimensional Monot...
 
Write down the four (4) nonlinear regression models covered in class,.pdf
Write down the four (4) nonlinear regression models covered in class,.pdfWrite down the four (4) nonlinear regression models covered in class,.pdf
Write down the four (4) nonlinear regression models covered in class,.pdf
 
Convolution
ConvolutionConvolution
Convolution
 
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
Turning Krimp into a Triclustering Technique on Sets of Attribute-Condition P...
 
A walk through the intersection between machine learning and mechanistic mode...
A walk through the intersection between machine learning and mechanistic mode...A walk through the intersection between machine learning and mechanistic mode...
A walk through the intersection between machine learning and mechanistic mode...
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 

Recently uploaded

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 

Recently uploaded (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 

Module System in Standard ML

  • 1. Module System of Standard ML Jiten, Keheliya, Tobias Tuesday 21st April, 2015 Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 1 / 39
  • 2. Outline 1 Modularity 2 Introduction to Standard ML 3 Modules in Standard ML Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 2 / 39
  • 3. Outline 1 Modularity 2 Introduction to Standard ML 3 Modules in Standard ML Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 3 / 39
  • 4. Why Modularity? Writing large programs is difficult! Lots of interdependencies Changing code breaks other code Concurrent development difficult Maintenance is a nightmare. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 4 / 39
  • 5. Why Modularity? Writing large programs is difficult! Lots of interdependencies Changing code breaks other code Concurrent development difficult Maintenance is a nightmare. The solution: Modularity Implement program as independent modules Hide information between modules to obscure implementation details (abstraction) Sharing: Interaction of program modules Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 4 / 39
  • 6. How do programmers use modularity in C? Write .h file (Header) and .c file (Source) Header specifies variables and functions Source is the full implementation Compile library from both files and provide Header file as interface. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 5 / 39
  • 7. Outline 1 Modularity 2 Introduction to Standard ML 3 Modules in Standard ML Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 6 / 39
  • 8. History of Standard ML ML (stands for metalanguage) Developed in Edinburgh in late ’70s Designed by Michael J.C. Gordon, Robin Milner, and Christopher P. Wadsworth Standard ML (originated from ML) Has a formal specification, given as typing rules and operational semantics The Definition of Standard ML (Revised) in 1997 Other siblings of the family: CAML, Caml Light, OCaml Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 7 / 39
  • 9. Features of Standard ML Higher-order functions Interactive Strongly Typed Call-by-value Polymorphism Algebraic datatypes and pattern matching Statically scoped Type-safe exceptions Modularity Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 8 / 39
  • 10. Language Basics Primitive Data Types: unit,bool,int,real,string Function Expressions val inc = fn x => x + 1 fun inc x = x + 1 Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 9 / 39
  • 11. Tuples, Records, Lists Tuples > val x = ("Prius", 1.0 / 2.0, false) : string * real * bool Records > val dob = {day=21,month="July",year="1815"} : {day:int, month:string, year:string} Lists > val price = [1.0,2.0,3.0]; > val price = 1.0 :: 2.0 :: 3.0 :: nil val price = [1.0,2.0,3.0] : real list Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 10 / 39
  • 12. Higher-order Functions Functions can consume functions as arguments fun applyTwice f x = f(f(x)); Functions can return functions val add = fn x => fn y => x + y Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 11 / 39
  • 13. Static Scoping What is the output of this program? val x = 2 fun f y = x+y val x = 3 val z = f 4 Refers to the nearest lexically enclosing declaration! Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 12 / 39
  • 14. Type Inference Examples of type inference fun ident (x) = x; val ident = fn : ’a -> ’a fun plus (x,y) = x+y; val plus = fn : int * int -> int fun new_if(A,B,C) = if A then B else C; val new_if = fn : bool * ’a * ’a -> ’a fun first (x,y) = x; val first = fn : ’a * ’b -> ’a ’a standing for any type at all. Function body makes no commitment to type of x at all. Type inference produces the most general type, which may be polymorphic. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 13 / 39
  • 15. Pattern Matching Wildcard Patterns val (x,y,_) = (4,"May",1987); val x = 4 : int val y = "May" : string Nested Patterns val (a,b)::c::_ = [(3,true),(5,false),(9,false)]; val a = 3 : int val b = true : bool val c = (5,false) : int * bool Function definition by cases fun is_nil( nil ) = true | is_nil(_::_) = false; Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 14 / 39
  • 16. Recursive Types datatype ’a tree = empty | leaf of ’a | node of ’a tree * ’a tree; datatype ’a list = nil | :: of ’a * ’a list; fun append(nil,l) = l | append(hd::tl,l) = hd :: append(tl,l); Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 15 / 39
  • 17. Recursive Typing To type infinte data-structures (Lists, queues, trees, streams etc.) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 16 / 39
  • 18. Recursive Typing To type infinte data-structures (Lists, queues, trees, streams etc.) Without Recursive typing:- t ::“ nilT | consT t t | headT t | tailT t v ::“ nilT | consT v v T ::“ List T Γ $ t1 : T1 Γ $ t2 : List T1 Γ $ consT1 t1 t2 : List T1 (T-cons) Γ $ t1 : List T1 Γ $ headT1 t1 : T1 (T-head) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 16 / 39
  • 19. Recursive Typing To type infinte data-structures (Lists, queues, trees, streams etc.) Without Recursive typing:- t ::“ nilT | consT t t | headT t | tailT t v ::“ nilT | consT v v T ::“ List T Γ $ t1 : T1 Γ $ t2 : List T1 Γ $ consT1 t1 t2 : List T1 (T-cons) Γ $ t1 : List T1 Γ $ headT1 t1 : T1 (T-head) Recursive typing:- T ::“ X | rec X.T Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 16 / 39
  • 20. Recursive Typing To type infinte data-structures (Lists, queues, trees, streams etc.) Without Recursive typing:- t ::“ nilT | consT t t | headT t | tailT t v ::“ nilT | consT v v T ::“ List T Γ $ t1 : T1 Γ $ t2 : List T1 Γ $ consT1 t1 t2 : List T1 (T-cons) Γ $ t1 : List T1 Γ $ headT1 t1 : T1 (T-head) Recursive typing:- T ::“ X | rec X.T IntList “ rec X. xnil : Unit, cons : tInt, Xuy Nat “ rec X. xZero : Unit, succ : Xy Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 16 / 39
  • 21. Recursive Typing... t ::“ foldT t | unfoldT t v ::“ foldT v unfoldS pfoldT vq ÝÑ v(E-unfldfld) U “ rec X.T1 Γ $ t1 : rU{XsT1 Γ $ foldU t1 : U (T-fld) U “ rec X.T1 Γ $ t1 : U Γ $ unfoldU t1 : rU{XsT1 (T-unfld) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 17 / 39
  • 22. Recursive Typing... t ::“ foldT t | unfoldT t v ::“ foldT v unfoldS pfoldT vq ÝÑ v(E-unfldfld) U “ rec X.T1 Γ $ t1 : rU{XsT1 Γ $ foldU t1 : U (T-fld) U “ rec X.T1 Γ $ t1 : U Γ $ unfoldU t1 : rU{XsT1 (T-unfld) nil “ foldrIntLists xnil “ unity cons = λn : Int.λl : IntList.foldrIntLists xcons “ tn, luy Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 17 / 39
  • 23. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 24. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X pλx : T11.t12q v2 rv2{xst12 pλX.t12q rT2s rT2{Xst12 Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 25. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X pλx : T11.t12q v2 rv2{xst12 pλX.t12q rT2s rT2{Xst12 Γ, X $ t2 : T2 Γ $ λX.t2 : @X.T2 (T-Tabs) Γ $ t1 : @X.T12 Γ $ t1 rT2s : rT2{XsT12 T-Tapp) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 26. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X pλx : T11.t12q v2 rv2{xst12 pλX.t12q rT2s rT2{Xst12 Γ, X $ t2 : T2 Γ $ λX.t2 : @X.T2 (T-Tabs) Γ $ t1 : @X.T12 Γ $ t1 rT2s : rT2{XsT12 T-Tapp) Example:- @X. rec Y. xnil : Unit, cons : tX, Yuy Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 27. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X pλx : T11.t12q v2 rv2{xst12 pλX.t12q rT2s rT2{Xst12 Γ, X $ t2 : T2 Γ $ λX.t2 : @X.T2 (T-Tabs) Γ $ t1 : @X.T12 Γ $ t1 rT2s : rT2{XsT12 T-Tapp) Example:- @X. rec Y. xnil : Unit, cons : tX, Yuy Polymorphism in ML:- Self-Application: Type of λx.x x? Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 28. Parametric Polymorphism t ::“ x | λx : T.t | t t | λX.t | t rTs v ::“ λx : T.t | λX.t T ::“ X | T Ñ T | @X.T Γ ::“ Φ | Γ, x : T | Γ, X pλx : T11.t12q v2 rv2{xst12 pλX.t12q rT2s rT2{Xst12 Γ, X $ t2 : T2 Γ $ λX.t2 : @X.T2 (T-Tabs) Γ $ t1 : @X.T12 Γ $ t1 rT2s : rT2{XsT12 T-Tapp) Example:- @X. rec Y. xnil : Unit, cons : tX, Yuy Polymorphism in ML:- Self-Application: Type of λx.x x? λx : @X.X Ñ X. x r@X.X Ñ Xs x : p@X.X Ñ Xq Ñ p@X.X Ñ Xq Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 18 / 39
  • 29. Example: Stack exception EmptyStack; val empty = []; fun push x r = x::r; fun pop r = case r of x::s => (x,s) | [] => raise EmptyStack; Type of push: ’a -> ’a list -> ’a list Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 19 / 39
  • 30. Example: Stack Type of push: ’a -> ’a list -> ’a list This exposes the implementation datastructure (list)! We want the view of the type to be abstract: ’a -> ’a stack -> ’a stack ñ Need Standard ML’s abstract types in modules. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 20 / 39
  • 31. Outline 1 Modularity 2 Introduction to Standard ML 3 Modules in Standard ML Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 21 / 39
  • 32. Signatures Signatures encode structural information Specify a module’s value and function types Provided explicitly by the programmer or discovered by type inference signature EQ = sig type elem val eq: elem * elem -> bool end; Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 22 / 39
  • 33. Structures structure is Standard ML’s Module structure IntEq : EQ = struct type elem = int val eq = (op =) end; Here, the signature is specified explicitly. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 23 / 39
  • 34. All put together: Signature, Module and Access signature EQ = sig type elem val eq: elem * elem -> bool end; structure IntEq : EQ = struct type elem = int val eq = (op =) end; IntEq.eq(3,4); IntEq.eq(4,4); Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 24 / 39
  • 35. Structures with explicit Signatures (1) structure IntEq : EQ means that the structure’s inferred signature is checked against the signature EQ IntEq must provide at least what’s in EQ. signature EQ = sig type elem val eq: elem * elem -> bool end; structure IntEq : EQ = struct type elem = int end; > Error: unmatched value specification: eq Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 25 / 39
  • 36. Structures with explicit Signatures (2) We can make structure IntEq more powerful than EQ. But the view is still restricted by the explicit signature EQ. signature EQ = sig type elem val eq: elem * elem -> bool end; structure IntEq : EQ = struct type elem = int val eq = (op =) val internalvalue = 1337 end; IntEq.internalvalue; > Error: unbound variable or constructor: internalvalue in path IntEq.internalvalue Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 26 / 39
  • 37. Opaque vs. Transparent Signatures (1) Remember we could evaluate IntEq.eq(3,4);? IntEq has signature EQ, which means IntEq.eq takes elem variables as parameter – not integers! Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 27 / 39
  • 38. Opaque vs. Transparent Signatures (1) Remember we could evaluate IntEq.eq(3,4);? IntEq has signature EQ, which means IntEq.eq takes elem variables as parameter – not integers! Well duh, calling with integers works, since IntEq.elem = int. Signatures are transparent. We can make them opaque to strictly restrict the view of IntEq to EQ. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 27 / 39
  • 39. Opaque vs. Transparent Signatures (2) structure IntEq :> EQ = struct type elem = int val eq = (op =) end; IntEq.eq(3,4); > Error: operator and operand don’t agree [literal] operator domain: IntEq.elem * IntEq.elem operand: int * int in expression: IntEq.eq (3,4) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 28 / 39
  • 40. Stack Module signature STACK = sig type ’a stack val empty: ’a stack val push: ’a -> ’a stack -> ’a stack val pop: ’a stack -> ’a * ’a stack end; structure stack :> STACK = struct exception EmptyStack; type ’a stack = ’a list; val empty = []; fun push x r = x::r; fun pop r = case r of x::s => (x,s) | [] => raise EmptyStack; end; Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 29 / 39
  • 41. Stack Module stack.push now has type: ’a -> ’a stack.stack -> ’a stack.stack. Thanks to opaqueness, stack.push 3 [5]; is illegal. Implementation protected. Yay! Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 30 / 39
  • 42. Functors A Functor takes a Structure as an argument and returns a Structure. They are defined using functor bindings at the top level (like function definitions) Limited to a single argument (Workaround: Several structures can be packaged into one as substructures and then passed to a functor) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 31 / 39
  • 43. Functors: Example functor F( P: EQ ) : EQ = struct type t = P.t * P.t fun eq((x,y),(u,v)) = P.eq(x,u) andalso P.eq(y,v) end; structure IntEq : EQ = struct type t = int val eq = (op =) end; structure IntTupleEq = F(IntEq); IntTupleEq.eq((3,4),(3,4)); Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 32 / 39
  • 44. Functors with Submodules: Example What if we want tuples of two different datatypes? For instance tuples of Integers and Strings: eq((3,"a"),(3,"c")) First, we introduce StringEq, similarly to IntEq: structure StringEq : EQ = struct type t = string val eq = (op =) end; Problem: functors only take a single structure as an argument. We need to pass IntEq and StringEq! Solution: Create a module containing both. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 33 / 39
  • 45. Functors with Submodules: Example signature TupleOfEQ = sig structure first : EQ structure second : EQ end; functor F( P: TupleOfEQ ) : EQ = struct type t = P.first.t * P.second.t fun eq((x,y),(u,v)) = P.first.eq(x,u) andalso P.second.eq(y,v) end; structure IntStringTuple : TupleOfEQ = struct structure first = IntEq structure second = StringEq end; structure IntStringTupleCombined = F(IntStringTuple); IntStringTupleCombined.eq((3,"a"),(3,"c")); Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 34 / 39
  • 46. Sums and Products :- Πx : A.B “ ą t Bpxq | x P A u Σx : A.B “ t Bpxq | x P A u Elements of Πx : A.B fpaq “ ra{xsB. Elements of Σx : A.B xa, by , a P A, b “ ra{xsB. Strong sums: sndppq : Bpfstppqq fstppq “ a. Corresponds to the transparent signatures. Weak sums: Corresponds to the opaque ascription. A form of existential type. Transclucent sums:- Optionally contain information about the representation of type. Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 35 / 39
  • 47. Module system Calculus Syntax:- K ::“ Ω | K ñ K1 A ::“ α | Πx : A.A1 | D1, .., Dn | λα :: K | AA1 | V.b D ::“ b Ź α :: K | b Ź α :: K “ A | y Ź x : A M ::“ x | λx : A.M | MM1 | M : A | B1, .., Bn | M.y B ::“ b Ź α “ A | y Ź x “ M V ::“ x | λx : A.M | Bv1, .., Bvn | V.y Bv ::“ b Ź α “ A | y Ź x “ V Γ ::“ ˝ | Γ, α :: K | Γ, α :: K “ A | Γ, x : A Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 36 / 39
  • 48. Module system Calculus Syntax:- K ::“ Ω | K ñ K1 A ::“ α | Πx : A.A1 | D1, .., Dn | λα :: K | AA1 | V.b D ::“ b Ź α :: K | b Ź α :: K “ A | y Ź x : A M ::“ x | λx : A.M | MM1 | M : A | B1, .., Bn | M.y B ::“ b Ź α “ A | y Ź x “ M V ::“ x | λx : A.M | Bv1, .., Bvn | V.y Bv ::“ b Ź α “ A | y Ź x “ V Γ ::“ ˝ | Γ, α :: K | Γ, α :: K “ A | Γ, x : A Example:- t elem Ź elem “ int, eq Ź eq “ λx : pelem ˚ elemq.pop “q, ival Ź ival “ 1337 u : t elem Ź elem :: Ω “ int, eq Ź eq : pelem, elemq Ñ bool u Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 36 / 39
  • 49. Module system Calculus.. Introduction and elimination rules:- $ Γvalid @i P r1.ns. Γ, D1, .., Di´1 $ Bi : Di Γ $ B1, .., Bn : D1, .., Dn (TSUM) Γ $ V : b Ź α :: K Γ $ V.b :: K (C-EXT-O) Γ $ M : y Ź x : A Γ $ M.y : A (EXT-V) Translucency:- Γ $ V : b Ź α :: K “ A Γ $ V.b “ A :: K (ABBREV) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 37 / 39
  • 50. Module system Calculus.. Value Rules:- Γ $ V : b Ź α :: K, D1, .., Dn Γ $ V : b Ź α :: K “ V.b, D1, .., Dn (VALUE-O) Γ $ V.y : A1 Γ $ V : y Ź x : A, D1, .., Dn Γ $ V : y Ź x : A1, D1, .., Dn (VALUE-V) Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 38 / 39
  • 51. Summary and Outlook ML has a powerful module system, using signatures, structures and functors Modules in ML are not part of the core language Beyond ML Modules: Recursive modules, higher-order functors, applicative functors Jiten, Keheliya, Tobias Module System of Standard ML Tuesday 21st April, 2015 39 / 39