Questions tagged [sml]

Standard ML is a high-level functional language with type inference.

Standard ML

Standard ML is a polymorphic high-level functional language with compile-time type checking and type inference. It is a strict language with immutable data types, updateable references, abstract data types and parametric modules. It has a proper module system that provides a powerful mechanism for creating, using and reusing programming abstractions, unlike Haskell who's "[...] module system serves primarily as a mechanism for namespace management [...]"(A Formal Specification of the Haskell 98 Module System). It has efficient implementations (approaching that of C) and a formal definition with a proof of soundness.

History

The first version of Standard ML was proposed in 1983 and designed in 1984-88 with the definition being published in 1990, thus also named SML '90.

A revised definition was published in 1997, which came with some simplifications and the addition of the SML Basis Library (see below).

For more information see History of Standard ML

Implementations

There are multiple implementations

Standard ML of New Jersey

  • The most popular implementation
  • Abbreviated SML/NJ
  • Written in Standard ML (except for the runtime system, which is written in C)
  • Uses Matthias Blume's Compilation Manager, CM, to greatly simplify the development of large software projects.
  • A variety of general-purpose data structures, algorithms and utilities (such as finite sets and maps, regular expressions, pretty-printing) are provided by the SML/NJ library.
  • Concurrent programming in SML is supported by the Concurrent ML library.

Moscow ML

  • Implementation based on code from Caml Special Light

MLton

  • Compiler that uses whole-program optimisation (i.e., there is no interpreter)
  • Supports ML Basis Files, to compile large programs
  • Their site (the homepage is one big "wiki") contains some pretty awesome insights, code and general comments on SML

PolyML

  • Compiler and library written in Standard ML, runtime system written in C++
  • Includes a source-level debugger
  • Supports multicore hardware: ML threads and parallel GC
  • Supports modern IDEs (compiler messages, inferred types, goto definitions, identifier scopes, completion etc.)

ML Kit

  • Uses region analysis for memory management.
  • Supports ML Basis Files, to compile large programs
  • Efficient compilation of modules by using a compilation scheme called Static Interpretation, which eliminates modules entirely at compile time.
  • Includes a graphical region profiler, which helps gain detailed control over memory reuse

HaMLet

HaMLet is a faithful and complete implementation of the Standard ML programming language (SML'97). It aims to be:

  • an accurate reference implementation of the language specification,
  • a platform for experimentation with the language semantics or extensions to it,
  • a useful tool for educational purposes.

MLj

MLj is a compiler for Standard ML which produces Java bytecodes.

MLtoJs

It's a compiler from Standard ML to JavaScript, which allows programmers to enjoy the power of Standard ML static typing, higher-order functions, pattern matching, and modules for programming client-side web applications.

MLWorks

MLWorks is a Standard ML compiler and development environment.

CakeML

A verified implementation of a significant subset of Standard ML.

SML#

ML# is a new programming language in the Standard ML family being developed at RIEC (Research Institute of Electrical Communication), Tohoku University . Its design goal is to provide practically important extensions while maintaining the compatibility of the Definition of Standard ML.

Manticore

Manticore is a high-level parallel programming language aimed at general-purpose applications running on multi-core processors. Manticore supports parallelism at multiple levels: explicit concurrency and coarse-grain parallelism via CML-style constructs and fine-grain parallelism via various light-weight notations, such as parallel tuple expressions and NESL/Nepal-style parallel array comprehensions.

SML Basis Library

The SML Basis Library provides interfaces and operations for basic types, such as integers and strings, support for input and output (I/O), interfaces to basic operating system interfaces, and support for standard datatypes, such as options and lists. The Library does not attempt to define higher-level APIs, such as collection types or graphical user-interface components. These APIs are left for other libraries.

The most recent version of the Basis Library (signature) specification is available at http://www.standardml.org/Basis/. Clarifications, corrections and additions are sometimes done.

Getting started

  1. Download one of the implementations mentioned above.

  2. Check out these Stack Overflow questions with links to popular websites, books, and tutorials:

  3. Have fun, and ask questions!

Examples

Factorial:

   fun factorial 0 = 1
     | factorial n = n * factorial (n - 1)

Printing text

 val _ = print "Hello, world!\n"

Books

Other References

2080 questions
0
votes
1 answer

Should the patterns in a SML match expression have the same type?

In Ullman's SML book: A match expression consists of one or more rules, which are pairs of the form => The rules are separated by vertical bars, so the form of a match is: => | =>…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
1 answer

How to read pair by pair from a file in SML?

I want to read N pairs from a file and store them as a tuples in a list.For example if i have these 3 pairs : 1-2 , 7-3, 2-9 i want my list to look like this -> [(1,2),(7,3),(2-9)] I tried something like this: fun ex filename = let fun…
panakran
  • 13
  • 3
0
votes
1 answer

SML BFS traversal for (int list array) Graph

I want to create a function in SML that does a BFS traversal of an undirected graph e.x Graph = [|[2],[3,4],[1,2],[2]|]. fun bfs (g: graph) (n: vertex): vertex list = let fun helper (todo: vertex list) (visited: vertex list) = case todo of …
0
votes
1 answer

Can I create an Array with an Int64?

I basically want to create an array (Array.array(k + 1, 1)) but because k is of type Int64 (it has to be), I can't create the array (gives error), so I am trying to find a way to bypass that error. Any Ideas? P.s the values of k < 20000 but it has…
0
votes
1 answer

List of sums of pairs

So I am given the following question and i am havign an incredibly hard time figuring out how to start... can someone help me ? So far my references are : https://www.cl.cam.ac.uk/~lp15/MLbook/pub-details.html (Essentially chapter 3) Write an ML…
0
votes
1 answer

In SML, does every variable denotes a reference?

In C , every variable denotes a reference, and we can get the reference from a variable by operator &. e.g. if int x=1, then &x is the reference denoted by variable x. every variable is evaluated to the value referred to the reference. e.g. x is…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
1 answer

Can we get the reference denoted by a variable in SML?

in SML, consider side effect by references. Is it correct that any variable (whether used with or without side effect) denotes a reference which then refers to a value? is it possible to get the reference denoted by a variable? Is there an…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
2 answers

SML Date structure

I've been trying to figure out random number generation in SML. There's a standard library function that requires a fresh seed for each calculation let val seed = Random.rand (123,456) in List.tabulate(5, fn i => Random.randRange (1,100) …
147pm
  • 2,137
  • 18
  • 28
0
votes
1 answer

SML pattern matching different constructors

I have the code below, and I am confused on why it is not compiling. I understood pattern matching can be used to match against different kinds of constructors, and as long as the expressions on the right side return the same type, it should be…
Payam Mesgari
  • 953
  • 1
  • 19
  • 38
0
votes
3 answers

SML consing a datatype list

If I have this SML datatype datatype json = Num of real | String of string | False | True | Null | Array of json list | Object of (string * json) list Let's say I have this Array with only one…
147pm
  • 2,137
  • 18
  • 28
0
votes
1 answer

SML function as lookup table

While delving into types in SML I found this fun monthI2S 1 = "January" | monthI2S 2 = "February" | monthI2S 3 = "March" | monthI2S 4 = "April" | monthI2S 5 = "May" | monthI2S 6 = "June" | monthI2S 7 = "July" | monthI2S 8 = "August" …
147pm
  • 2,137
  • 18
  • 28
0
votes
1 answer

SML list decomposition issue

I found the old U of Washington course CSE341: Programming Languages and am trying to follow along just so I can one day tackle Paulson's ML for the Working Programmer. So I have this: fun number_in_month5 (m : int, ms : (int*int*int) list) = …
147pm
  • 2,137
  • 18
  • 28
0
votes
1 answer

infinite sequence in SML

I have to code a function that receives a sequence (finite or infinite) and returns an identical sequence with the only difference that if an exception occurs during the sequence then the function returns the sequence to its beginning. In other…
Arie
  • 23
  • 5
0
votes
0 answers

To distribute a list according to a condition in sml environment

Given a randomly ordered array of n elements partition the elements into two subsets such that elements less than x are in one subset and elements greater than x are in separate subset. For instance, [28, 26, 25, 11, 16, 12, 24, 29, 6, 10] and x =…
0
votes
2 answers

SML functions as values

I'm experimenting with this in SML - val p = (fn (x,y) => x + y, fn (x,y) => x - y) val p = (fn,fn) : (int * int -> int) * (int * int -> int) But I may only evaluate it one at a time - #1(p)(3,2) 5 or - #2(p)(3,2) 1 Why can I not do both? -…
147pm
  • 2,137
  • 18
  • 28