Runs about 20 pages. Highly recommended to have with you when hacking. Lecture 2 has many nice examples of use of the modules system, and lecture 3 is the best explanation I have seen of the static semantics of modules signature matching and constraints. As of [], the web site for the entire workshop series has not been updated since just before ML The series however has continued with ML and ML This gives an alternative to SML's built-in tuples which are actually records with numeric field labels.
The point is that it lets you define functions that operate on tuples of arbitrary size in an inductive fashion. This discusses how to define functions that can take an arbitrary number of curried arguments, i. This is an advanced use of the fold pattern that deals with some special cases that can sometimes arise for which fold itself is not enough. This gives you polymorphic functions over tuples built with the user-defined binary product operator mentioned above.
The Standard ML Programming Language
SML's built-in tuples records with numeric field labels are not handled by this pattern. Can they be handled some other way? This web page also discusses how Berthomieu's method fails due to type system restrictions for classes where the non-constructor methods of the class might need to call a constructor of the same class. You can learn about SML from the following resources. The table of features on this web page is missing a lot of entries for SML.
This list only includes SML implementations that have been made available to the public. After processing each declaration, the REPL will ask the user for more. Allows turning SML into a library that can be called from C or any other language that can call C libraries?
The Standard ML Programming Language
Only quite strange SML code would detect the difference. The SML run-time support code must have the list of C functions that can be called compiled into it. The interface is simple, i. Anything complex passed to C must be presumed to live forever and can not be garbage collected. Can build and handle arbitrary C data structures in SML code. Can manage memory of C data structures.
If you know something is not used, you can free it. Very complex types but presumably a type error slicer will help a lot here. In principle, you could use the same method the other FFI uses to wrap SML closures so they can be called from C, but you would have to do it by hand. Must manage memory of C data structures. Disallows non-datatype uses of datatype replication.
Handles the value polymorphism restriction incorrectly in some cases. Slides from the presentation are also available. A Source To Source Translator. Ken Larsen and Henning Niss. MS Project Report, A detailed explanation of the design and implementation of a bytecode compiler and interpreter for ML with a machine model aimed at efficient implementation. Polymorphism by Name for References and Continuations. Allen Leung and Lal George. Asynchronous Exceptions in Haskell. An asynchronous exception is a signal that one thread can send to another, and is useful for the receiving thread to treat as an exception so that it can clean up locks or other state relevant to its current context.
That About Wraps it Up: The full report is only available in Danish. A Theory of Type Polymorphism in Programming. Journal of Computer and System Sciences, Robin Milner and Mads Tofte. The Definition of Standard ML. Accompanied by the Commentary on Standard ML. Principles and a Preliminary Design for ML The ML working group, Gregory Morrisett and Andrew Tolmach. Scottish Functional Programming Workshop, Huu-Duc Nguyen and Atsushi Ohori.
Standard ML
Purely Functional Data Structures. Atsushi Ohori and Tomonobu Takamizawa. Type-Directed Specialization of Polymorphism. System Description and Performance Evaluation. Describes a native x86 Erlang compiler and a comparison of many different native x86 compilers including MLton and their register usage and call stack implementations. Reactive Programming in Standard ML. Concurrent Programming in ML. An Expressive Language of Signatures. Kevin Redwine and Norman Ramsey. Describes a method to implement numeric types and operations like Int31 or Word17 for sizes smaller than that provided by the processor.
Synchronous Operations as First-Class Values. Concurrent Programming in ML addall. Workshop on the Parallel Implementation of Functional Languages, Kevin Scott and Norman Ramsey. Zhong Shao and Andrew W. Calcul Statique des Applications de Modules Parametres. Describes a defunctorizer for OCaml, and compares it to existing defunctorizers, including MLton.
Incremental Execution of Transformation Specifications. Tarditi and Andrew W. Compiling Standard ML to C. Object-oriented programming and Standard ML. Lars Thorup and Mads Tofte. Type Inference for Polymorphic References.
Essentials of Standard ML Modules. A more efficient implementation of map would define a tail-recursive inner loop as follows: Exceptions are raised with the raise keyword, and handled with pattern matching handle constructs. The exception system can be exploited to implement non-local exit , an optimization technique suitable for functions like the following. When the exception Zero is raised in the 0 case, control leaves the function p altogether.
The raising of the exception allows control to leapfrog directly over the entire chain of frames and avoid the associated computation. It has to be noted that the same optimization could have been obtained by using a tail recursion for this example. Standard ML has an advanced module system, allowing programs to be decomposed into hierarchically organized structures of logically related type and value declarations. SML modules provide not only namespace control but also abstraction, in the sense that they allow programmers to define abstract data types.
Three main syntactic constructs comprise the SML module system: A structure is a module; it consists of a collection of types, exceptions, values and structures called substructures packaged together into a logical unit.
Account Options
A signature is an interface , usually thought of as a type for a structure: The definitions of type components may or may not be exported; type components whose definitions are hidden are abstract types. Finally, a functor is a function from structures to structures; that is, a functor accepts one or more arguments, which are usually structures of a given signature, and produces a structure as its result.
Functors are used to implement generic data structures and algorithms.
For example, the signature for a queue data structure might be:. This signature describes a module that provides a parameterized type queue of queues, an exception called QueueError , and six values five of which are functions providing the basic operations on queues. One can now implement the queue data structure by writing a structure with this signature:. Furthermore, the opaque ascription denoted by: The body of the structure provides bindings for all of the components listed in the signature.
To use a structure, one can access its type and value members using "dot notation". For instance, a queue of strings would have type string TwoListQueue. One popular algorithm [4] for breadth-first search of trees makes uses of queues.
- The Captain (Zebra Regency Romance).
- I Missed the Spring.
- Correr para vivir, vivir para correr: De cómo el running puede mejorar la vida de las personas (Spanish Edition).
Here we present a version of that algorithm parameterized over an abstract queue structure:. Please note that inside the BFS structure, the program has no access to the particular queue representation in play. More concretely, there is no way for the program to, say, select the first list in the two-list queue representation, if that is indeed the representation being used.
This data abstraction mechanism makes the breadth-first code truly agnostic to the queue representation choice. This is in general desirable; in the present case, the queue structure can safely maintain any of the various logical invariants on which its correctness depends behind the bulletproof wall of abstraction. For numerical computing, a Matrix module exists but is currently broken , http: For graphics, cairo-sml is an open source interface to the Cairo graphics library. This is an interactive session that prints the inferred types of resulting or defined expressions.
References
This can be made polymorphic by abstracting over the ordering operator. Here, the classic mergesort algorithm is implemented in three functions: The function split is implemented with a local function named loop , which has two additional parameters. The local function loop is written in a tail-recursive style; as such it can be compiled efficiently. This function makes use of SML's pattern matching syntax to differentiate between non-empty list x:: For stability, the input list ns is reversed before being passed to loop.
The local-in-end syntax could be replaced with a let-in-end syntax, yielding the equivalent definition:. As with split, merge also uses a local function loop for efficiency. The inner loop is defined in terms of cases: This function merges two "ascending" lists into one ascending list. Note how the accumulator out is built "backwards", then reversed with List.
This is a common technique—build a list backwards, then reverse it before returning it.