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
2 answers

SML merge_sort function using let in and pattern matching

fun merge_sort (_, nil) = nil | merge_sort (_, [a]) = [a] | merge_sort (f, L) = let fun halve nil = (nil,nil) | halve [a] = ([a], nil) | halve (a :: b :: rest) = let val (x , y) =…
Cheeki
  • 75
  • 4
0
votes
2 answers

recursion compilation error in Standard ML

I am making a function that recurses over a string and replaces each instance of a user-specified character. However, I get a compilation error of : Error: operator and operand do not agree [tycon mismatch] operator domain: string * string …
Alejandro
  • 623
  • 1
  • 9
  • 22
0
votes
2 answers

number_in_month exercise (Getting EQUAL. OP Error in SML, One function works other does not)

(* Write a function number_in_month that takes a list of dates and a month (i.e., an int) and returns how many dates in the list are in the given month.*) fun number_in_month(datelist : (int*int*int) list, month : int) = if null(tl (datelist)) …
hagenek
  • 108
  • 1
  • 6
0
votes
1 answer

Simple function with internal state

I would like to write a minimal function with an internal state. It should have signature f: () -> () and the n-th time it is called should print the number n. I imagine that refs are necessary, but I do not know how to use them to make such a…
afiori
  • 465
  • 3
  • 15
0
votes
1 answer

Does SML support guards on patterns within match expressions?

I've in mind something akin to the F# mechanism described here. In looking into it, I've found nothing explicitly saying it does nor that it doesn't.
0
votes
1 answer

Finding middle element in a Standard ML list

I am trying to find the middle element of a list in SML without using any pre implemented functions of the form List.whatever. I can use a function that takes 2 of the same lists, recursively calls itself, removing one item from one list and 2 items…
Defqon777
  • 49
  • 1
  • 5
0
votes
1 answer

How can I parametrize this function to accept a function and TextIO.closeOut as input?

Is it possible to parametrize this aux function to accept both TextIO.closeOut outstream and readFileList xs outstream n as input? Or must I use that append function in TextIO to have a less ugly function body? Is it possible to match their…
0
votes
1 answer

Find all valid addresses of a tree in SML

I want to write a procedure which delivers all valid addresses of a simple tree in SML. The datastructure of a tree in this case is: datatype tree = T of tree list What I have up till now is: fun address (T ts) = (rev (#2(foldl (fn (s,(sum, liste))…
Ultor
  • 7
  • 1
0
votes
1 answer

Completing code for dijkstra's code in ML

I need help completing this code: fun insertSorted(x, comp, []) = [x] | insertSorted(x, comp, a::rest) = ?? if written correctly it would return - insertSorted(5, fn(a, b) => a > b, [8, 6, 3, 1]); val it = [8, 6, 5, 3, 1] The code takes a value,…
0
votes
1 answer

several questions about this sml recursion function

When f(x-1) is called, is it calling f(x) = x+10 or f(x) = if ... Is this a tail recursion? How should I rewrite it using static / dynamic allocation? let fun f(x) = x + 10 in let fun f(x) = if x < 1 then 0 else f(x-1) in f(3) …
0
votes
1 answer

Creating A Dictionary In SML

I am newly Learner Of The SML Language. I Have Learned The Basics Of SML Language.But, I am having a Trouble In getting the code of creating a dictionary in SML. So, I Want To Know The code.
0
votes
1 answer

Creating different calculus functions in SML New Jersey

A) Write the function indefIntegratePoly which takes a list of coefficients standing for a polynomial (in the order from highest degree to lowest with all terms present) and returns a new list of ​coefficients standing for an indefinite integral of…
0
votes
1 answer

SML: Recursive addition test case syntax

I have written SML code to recursively add two numbers of datatype nat. A function peanify to convert integer to nat. A function decimal to convert nat to integer. Wanted help with syntax to test fun plus. Say I want to test for 2 + 1 datatype nat =…
hjuk12
  • 111
  • 5
0
votes
0 answers

Questions on how to write a function allLessThan in ML?

Write a function allLessThan. It takes two list of integers and test if all integers in the first list are less than all integers in the second list. For example allLessThan([2,4], [6,7,8]) would return true I've tried to set up the function in…
0
votes
1 answer

Write a SML function that take the name of a file and return a list of char without spaces

In an exam i found this exercise: "Write a function that take a file name (i.e. "text.txt") and return a list of char without blanks" For example: "text.txt" contains "ab e ad c" the function must return -> [#"a",#"b",#"e",#"a",#"d",#"c"] Which is…
Pater
  • 83
  • 1
  • 6
1 2 3
99
100