The Definition of Standard ML
The Definition of Standard ML
(Revised)
Robin Milner, Mads Tofte, Robert Harper and David MacQueen
The MIT Press
Cambridge, Massachusetts
London, England
c1997 Robin Milner
All rights reserved. No part of this book may be reproduced in any form
by any electronic or mechanical means (including photocopying, recording,
or information storage and retrieval) without permission in writing from the
publisher.
Printed and bound in the United States of America.
Library of Congress Cataloging-in-Publication Data
The definition of standard ML: revised / Robin Milner . . . et al.
p.
cm.
Includes bibliographical references and index.
ISBN 0-262-63181-4 (alk. paper)
1. ML (Computer program language)
I. Milner, R. (Robin), 1934-
QA76.73.M6D44 1997
005.133—dc21
97-59
CIP
Contents
1 Introduction
2 Syntax of the Core
2.1 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Special constants . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.4
Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.5 Lexical analysis . . . . . . . . . . . . . . . . . . . . . . . . . .
2.6
. . . . . . . . . . . . . . . . . . . . . . . . .
2.7 Derived Forms . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.8 Grammar
. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.9 Syntactic Restrictions . . . . . . . . . . . . . . . . . . . . . . .
Infixed operators
1
3
3
3
4
5
6
6
7
7
9
3 Syntax of Modules
12
3.1 Reserved Words . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.2
Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
. . . . . . . . . . . . . . . . . . . . . . . . . 12
3.3
Infixed operators
3.4 Grammar for Modules
. . . . . . . . . . . . . . . . . . . . . . 13
3.5 Syntactic Restrictions . . . . . . . . . . . . . . . . . . . . . . . 13
4 Static Semantics for the Core
16
4.1 Simple Objects
. . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2 Compound Objects . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 Projection, Injection and Modification . . . . . . . . . . . . . 17
4.4 Types and Type functions . . . . . . . . . . . . . . . . . . . . 19
4.5 Type Schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.6 Scope of Explicit Type Variables
. . . . . . . . . . . . . . . . 20
4.7 Non-expansive Expressions . . . . . . . . . . . . . . . . . . . . 21
4.8 Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.9 Type Structures and Type Environments . . . . . . . . . . . . 22
. . . . . . . . . . . . . . . . . . . . . . . . . . 23
4.10 Inference Rules
4.11 Further Restrictions
. . . . . . . . . . . . . . . . . . . . . . . 31
5 Static Semantics for Modules
33
5.1 Semantic Objects . . . . . . . . . . . . . . . . . . . . . . . . . 33
5.2 Type Realisation . . . . . . . . . . . . . . . . . . . . . . . . . 33
vi
CONTENTS
5.3 Signature Instantiation . . . . . . . . . . . . . . . . . . . . . . 34
5.4 Functor Signature Instantiation . . . . . . . . . . . . . . . . . 34
5.5 Enrichment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.6 Signature Matching . . . . . . . . . . . . . . . . . . . . . . . . 35
. . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.7
Inference Rules
6 Dynamic Semantics for the Core
43
6.1 Reduced Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.2 Simple Objects
. . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.3 Compound Objects . . . . . . . . . . . . . . . . . . . . . . . . 44
6.4 Basic Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.5 Basic Exceptions
. . . . . . . . . . . . . . . . . . . . . . . . . 45
6.6 Function Closures . . . . . . . . . . . . . . . . . . . . . . . . . 45
6.7
. . . . . . . . . . . . . . . . . . . . . . . . . . 46
Inference Rules
7 Dynamic Semantics for Modules
56
7.1 Reduced Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 56
7.2 Compound Objects . . . . . . . . . . . . . . . . . . . . . . . . 56
. . . . . . . . . . . . . . . . . . . . . . . . . . 58
7.3
Inference Rules
8 Programs
A Appendix: Derived Forms
B Appendix: Full Grammar
C Appendix: The Initial Static Basis
D Appendix: The Initial Dynamic Basis
64
67
75
81
84
E Overloading
86
E.1 Overloaded special constants . . . . . . . . . . . . . . . . . . . 86
E.2 Overloaded value identifiers
. . . . . . . . . . . . . . . . . . . 87
F Appendix: The Development of ML
89
G Appendix: What is New?
99
G.1 Type Abbreviations in Signatures . . . . . . . . . . . . . . . . 99
G.2 Opaque Signature Matching . . . . . . . . . . . . . . . . . . . 100
CONTENTS
vii
G.3 Sharing
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
G.3.1 Type Sharing . . . . . . . . . . . . . . . . . . . . . . . 102
G.3.2 The equality attribute of specified types
. . . . . . . . 103
G.3.3 Structure Sharing . . . . . . . . . . . . . . . . . . . . . 104
G.4 Value Polymorphism . . . . . . . . . . . . . . . . . . . . . . . 105
G.5 Identifier Status . . . . . . . . . . . . . . . . . . . . . . . . . . 106
G.6 Replication of Datatypes . . . . . . . . . . . . . . . . . . . . . 107
G.7 Local Datatypes . . . . . . . . . . . . . . . . . . . . . . . . . . 109
G.8 Principal Environments . . . . . . . . . . . . . . . . . . . . . . 110
G.9 Consistency and Admissibility . . . . . . . . . . . . . . . . . . 111
G.10 Special Constants . . . . . . . . . . . . . . . . . . . . . . . . . 111
G.11 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
G.12 Infixed Operators . . . . . . . . . . . . . . . . . . . . . . . . . 112
G.13 Non-expansive Expressions . . . . . . . . . . . . . . . . . . . . 112
G.14 Rebinding of built-in identifiers
. . . . . . . . . . . . . . . . . 112
G.15 Grammar for Modules
. . . . . . . . . . . . . . . . . . . . . . 112
G.16 Closure Restrictions . . . . . . . . . . . . . . . . . . . . . . . . 112
G.17 Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
G.18 Scope of Explicit Type Variables
. . . . . . . . . . . . . . . . 113
G.19 The Initial Basis
. . . . . . . . . . . . . . . . . . . . . . . . . 113
G.20 Overloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
G.21 Reals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
References
116