Programming in the large in ML Need mechanisms for –Modularization –Information hiding –Parametrization of interfaces While retaining type inference Modules:

Slides:



Advertisements
Similar presentations
More ML Compiling Techniques David Walker. Today More data structures lists More functions More modules.
Advertisements

Type Variables in ML Until we know the type of a value (perhaps never!), we use a variable for its type Book uses, e.g., t1, tx, tf PL literature uses.
Modules Program is built out of components. Each component defines a set of logically related entities (strong internal coupling) A component has a public.
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.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
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.
5/15/2015IT 3271 Polymorphism (Ch 8) n A functions that is not fixed is polymorphic n Applies to a wide variety of language features n Most languages have.
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.
Type Checking.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
1 The Design of Class Mechanism for MOBY. 2 Earlier Software designers have to choose between the following schemes for the development Earlier Software.
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
Introduction to ML A Quasi-Functional Language With Strong Typing And Type Inference.
Modules in UHC A proposal by: Tom Hofte & Eric Eijkelenboom.
Last Time Introduction Course Logistics Introduction to ML Base Types Tuples and Records Functions & Polymorphism See Harper ’ s Intro to ML.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Lecture 9 Concepts of Programming Languages
© Alan Burns and Andy Wellings, 2001 Programming in the Small Aim: to remind you how to read/write programs in Ada 95, Java and ANSI C.
Programming Languages: Design, Specification, and Implementation G Rob Strom October 19, 2006.
Abstract Data Types and Encapsulation Concepts
Introduction to ML A Quasi-Functional Language With Strong Typing And Type Inference.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
© Kenneth C. Louden, Chapter 9 – Abstract Data Types and Modules Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Existential Types and Module Systems Xiaoheng Ji Department of Computing and Software March 19, 2004.
CSC 580 – Theory of Programming Languages, Spring, 2009 Week 9: Functional Languages ML and Haskell, Dr. Dale E. Parson.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
1 SystemVerilog Enhancement Requests Daniel Schostak Principal Engineer February 26 th 2010.
PZ06C Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06C - Polymorphism Programming Language Design and.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Programming Languages Third Edition Chapter 11 Abstract Data Types and Modules.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Abstract Data Types and Modules Lecture 11 – ADT and Modules, Spring CSE3302 Programming.
1 Chapter 11 © 1998 by Addison Wesley Longman, Inc The Concept of Abstraction - The concept of abstraction is fundamental in programming - Nearly.
1 CS Programming Languages Class 22 November 14, 2000.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 10 Abstraction - The concept of abstraction is fundamental in programming - Nearly all programming.
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.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
Cs776 (Prasad)L2HOF1 Higher-Order Functions. cs776 (Prasad)L2HOF2 Higher-Order Functions A function that takes a function as argument and/or returns a.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
Type Checking and Type Inference
Principles of programming languages 12: Functional programming
Lecture 12 Inheritance.
ML: a quasi-functional language with strong typing
11.1 The Concept of Abstraction
slides created by Marty Stepp
Lecture 9 Concepts of Programming Languages
Objective caml Daniel Jackson MIT Lab for Computer Science 6898: Advanced Topics in Software Design March 18, 2002.
FP Foundations, Scheme In Text: Chapter 14.
value : type : function :: structure : signature : functor
CSE-321 Programming Languages Introduction to Functional Programming
CS 242 Types John Mitchell Reading: Chapter 6.
11.1 The Concept of Abstraction
Lecture 9 Concepts of Programming Languages
Chapter 11 Abstraction - The concept of abstraction is fundamental in
Presentation transcript:

Programming in the large in ML Need mechanisms for –Modularization –Information hiding –Parametrization of interfaces While retaining type inference Modules: like packages / namespaces Signatures: like package specifications /Java interfaces Functors: like generics with formal packages

Structures structure Complex = struct type t = real * real; val zero = (0.0, 0.0):t; (*qualification may be needed *) val i = (0.0, 1.0); fun sum ((x, y), (x1, y1)) = (x+x1, y+y1):t; fun prod ((x, y), (x1, y1)) = (x*x1 – y*y1, x*y1 + y*x1):t; fun inv ((x, y)) = let val den = x*x + y+y in (x / den, ~ y / den): t end; fun quo (z, z1) = prod (z, inv (z1)):t; end;

Using a structure - use (“complex.ml”); signature Complex : sig …. - Complex.prod (Complex.i, Complex.i); val it = (~1.0, 0.0); - val pi4 = (0.707, 0.707); val pi4 … real * real structural equivalence - Complex.prod (pi4, pi4); val it = … : Complex.t;

Signatures Interface description without implementation: signature CMPLX = sig type t val zero : t val i : t val sum : t * t -> t val diff : t * t -> t val prod : t * t -> t val inv : t -> t val quo : t * t -> t end

Multiple implementations structure complex1 : CMPLX = struct type t = real*real; (* cartesian representation *) val zero = (0.0, 0.0); val i = (0.0, 1.0); … Structure ComplexPolar: CMPLX = Struct type t = real*real (*polar representation*) val zero = (0.0, 0.0); val pi = ; val i := (0.0, pi / 2.0);

Information Hiding Only signature should be visible Declare structure to be opaque: structure polar :> CMPLX = …. (Structure can be opaque or transparent depending on context). Can export explicit constructors and equality for type. Otherwise, equivalent to limited private types in Ada. Can declare as eqtype to export equality

Functors Structures and signatures are not first-class objects. A program (structure) can be parametrized by a signature functor testComplex (C : CMPLX) = struct open C; (*equivalent to use clause*) fun FFT.. end; structure testPolar = testComplex (Complexpolar); (* equivalent to instantiation with a package *)

Imperative Programming in ML A real language needs operations with side effects, state, and variables Need to retain type inference - val p = ref 5; val p = ref 5 : int ref ; (* ref is a type constructor*) - !p * 2; (* dereference operation *) val it = 10: int; - p := !p * 3; val it = ( ) : unit (* assignment has no value *) References are equality types (pointer equality)

References and polymorphism fun Id x = x; (* id : ‘a -> ‘a *) val fp = ref Id; (*a function pointer *) fp := not; !fp 5 ; (* must be forbidden! *) In a top level declaration, all references must be monomorphic.