Preface......Page 3 I Overview......Page 11 1.1 A Regular Expression Package......Page 15 1.2 Sample Code......Page 23 II The Core Language......Page 29 2.1 Evaluation and Execution......Page 33 2.2 The ML Computation Model......Page 34 2.2.1 Type Checking......Page 35 2.2.2 Evaluation......Page 37 2.3 Types, Types, Types......Page 38 2.4 Type Errors......Page 40 3.1 Variables......Page 43 3.2.2 Value Bindings......Page 44 3.3 Compound Declarations......Page 46 3.4 Limiting Scope......Page 47 3.5 Typing and Evaluation......Page 48 4.1 Functions as Templates......Page 51 4.2 Functions and Application......Page 52 4.3 Binding and Scope, Revisited......Page 55 5.1.1 Tuples......Page 59 5.1.2 Tuple Patterns......Page 61 5.2 Record Types......Page 64 5.3 Multiple Arguments and Multiple Results......Page 66 6.1 Homogeneous and Heterogeneous Types......Page 69 6.2 Clausal Function Expressions......Page 70 6.3 Booleans and Conditionals, Revisited......Page 71 6.4 Exhaustiveness and Redundancy......Page 72 7 Recursive Functions......Page 75 7.1 Self-Reference and Recursion......Page 76 7.2 Iteration......Page 79 7.3 Inductive Reasoning......Page 80 7.4 Mutual Recursion......Page 83 8.1 Type Inference......Page 85 8.2 Polymorphic Definitions......Page 88 8.3 Overloading......Page 90 9.1 List Primitives......Page 95 9.2 Computing With Lists......Page 97 10.1 Datatype Declarations......Page 101 10.2 Non-Recursive Datatypes......Page 102 10.3 Recursive Datatypes......Page 104 10.4 Heterogeneous Data Structures......Page 107 10.5 Abstract Syntax......Page 108 11.1 Functions as Values......Page 111 11.2 Binding and Scope......Page 112 11.3 Returning Functions......Page 113 11.4 Patterns of Control......Page 116 11.5 Staging......Page 118 12.1 Exceptions as Errors......Page 121 12.1.1 Primitive Exceptions......Page 122 12.1.2 User-Defined Exceptions......Page 123 12.2 Exception Handlers......Page 124 12.3 Value-Carrying Exceptions......Page 128 13.1 Reference Cells......Page 131 13.2 Reference Patterns......Page 133 13.3 Identity......Page 134 13.4 Aliasing......Page 136 13.5 Programming Well With References......Page 137 13.5.1 Private Storage......Page 138 13.5.2 Mutable Data Structures......Page 139 13.6 Mutable Arrays......Page 141 14.1 Textual Input/Output......Page 145 15 Lazy Data Structures......Page 149 15.1 Lazy Data Types......Page 151 15.2 Lazy Function Definitions......Page 152 15.3 Programming with Streams......Page 154 16 Equality and Equality Types......Page 157 17 Concurrency......Page 159 III The Module Language......Page 161 18.1.1 Basic Signatures......Page 165 18.1.2 Signature Inheritance......Page 167 18.2.1 Basic Structures......Page 169 18.2.2 Long and Short Identifiers......Page 170 19 Signature Matching......Page 173 19.1 Principal Signatures......Page 174 19.2 Matching......Page 175 19.3 Satisfaction......Page 179 20.1 Ascribed Structure Bindings......Page 181 20.2 Opaque Ascription......Page 182 20.3 Transparent Ascription......Page 185 20.4 Transparency, Opacity, and Dependency......Page 187 21.1 Substructures......Page 189 22.1 Combining Abstractions......Page 197 23.1 Functor Bindings and Applications......Page 205 23.2 Functors and Sharing Specifications......Page 208 23.3 Avoiding Sharing Specifications......Page 210 IV Programming Techniques......Page 215 24.1 Specifications......Page 219 24.2 Correctness Proofs......Page 221 24.3 Enforcement and Compliance......Page 224 25.1 Exponentiation......Page 227 25.2 The GCD Algorithm......Page 232 26.1 Natural Numbers......Page 237 26.2 Lists......Page 239 26.3 Trees......Page 240 26.4 Generalizations and Limitations......Page 241 26.5 Abstracting Induction......Page 242 27.1 Regular Expressions and Languages......Page 245 27.2 Specifying the Matcher......Page 247 28 Persistent and Ephemeral Data Structures......Page 255 28.1 Persistent Queues......Page 258 28.2 Amortized Analysis......Page 261 29.1 The n-Queens Problem......Page 265 29.2 Solution Using Options......Page 267 29.3 Solution Using Exceptions......Page 268 29.4 Solution Using Continuations......Page 270 30 Higher-Order Functions......Page 273 30.1 Infinite Sequences......Page 274 30.2 Circuit Simulation......Page 277 31.1 Dictionaries......Page 281 31.2 Binary Search Trees......Page 282 31.3 Balanced Binary Search Trees......Page 283 31.4 Abstraction vs. Run-Time Checking......Page 287 32 Representation Independence and ADT Correctness......Page 291 33 Modularity and Reuse......Page 293 34 Dynamic Typing and Dynamic Dispatch......Page 295 35 Concurrency......Page 297 V Appendices......Page 299 The Standard ML Basis Library......Page 301 35.2 Building Systems with CM......Page 303 Sample Programs......Page 305