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

1944 questions
101
votes
2 answers

What are the differences between SML and OCaml?

What sets the two ML dialects apart?
Nathan
  • 1,021
  • 2
  • 8
  • 5
79
votes
8 answers

Haskell or Standard ML for beginners?

I'm going to be teaching a lower-division course in discrete structures. I have selected the text book Discrete Structures, Logic, and Computability in part because it contains examples and concepts that are conducive to implementation with a…
Barry Brown
  • 19,087
  • 14
  • 65
  • 102
64
votes
9 answers

Explaining pattern matching vs switch

I have been trying to explain the difference between switch statements and pattern matching(F#) to a couple of people but I haven't really been able to explain it well..most of the time they just look at me and say "so why don't you just use…
Nathan W
  • 50,657
  • 24
  • 92
  • 142
60
votes
3 answers

What are the primary theoretical difficulties with adding ML-style modules to Haskell?

It is well known that Haskell-style typeclasses and ML-style modules offer different mechanisms for specifying interfaces. They are (possibly) equivalent in power, but in practice each has their own benefits and drawbacks. Since I'm a bit of an…
Edward Z. Yang
  • 25,246
  • 16
  • 75
  • 102
48
votes
1 answer

SML-NJ, how to compile standalone executable

I start to learn Standard ML, and now I try to use Standard ML of New Jersey compiler. Now I can use interactive loop, but how I can compile source file to standalone executable? In C, for example, one can just write $ gcc hello_world.c -o…
S.J.
  • 1,163
  • 1
  • 11
  • 14
42
votes
3 answers

What's the difference (if any) between Standard ML's module system and OCaml module system?

My question is if there is any difference between Standard ML's module system and OCaml module system? Has OCaml all the support of functors , ascriptions etc... that SML has?
Dragno
  • 2,669
  • 23
  • 38
41
votes
1 answer

Encoding Standard ML modules in OO

The ML module system stands as a high-water mark of programming language support for data abstraction. However, superficially, it seems that it can easily be encoded in an object-oriented language that supports abstract type members. For example, we…
narthi
  • 2,120
  • 1
  • 16
  • 25
38
votes
1 answer

If SML.NET had functors why can't F#?

This question started out from My translating of "ML for the Working Programmer" (WorldCat) by L. C. PAULSON to F# which uses functors for the examples. Eventual desire to translate "Purely Functional Data Structures" (WorldCat) by Chris…
Guy Coder
  • 22,011
  • 6
  • 54
  • 113
36
votes
1 answer

Warning: calling polyEqual

Can somebody please explain, what does this warning means? stdIn:18.35 Warning: calling polyEqual and why do I have "a and not 'a in the following statement: val alreadyVisited = fn : ''a * ''a list -> bool this is my function: fun…
rookie
  • 7,085
  • 13
  • 42
  • 57
30
votes
5 answers

Can good type systems distinguish between matrices in different bases?

My program (Hartree-Fock/iterative SCF) has two matrices F and F' which are really the same matrix expressed in two different bases. I just lost three hours of debugging time because I accidentally used F' instead of F. In C++, the type-checker…
Wang
  • 2,987
  • 1
  • 18
  • 31
28
votes
1 answer

Growth of Type Definition in SML Using Hindley Milner Type Inference

Someone once showed me a little 'trick' in SML where they wrote out about 3 or 4 functions in their REPL and the resulting type for the last value was extremely long (like many page scrolls long). Does anyone know what code generates such a long…
27
votes
6 answers

ML IDE and Compiler for Windows or Linux or Mac

I have to write some code in ML and it is my first time I`m going to use the language. Is there any Development Environment for Standard ML? (preferably under Windows). I tried googling (and stackOverFlowing ! ) but all I found was plain compilers…
Sajad Bahmani
  • 16,531
  • 27
  • 81
  • 105
26
votes
1 answer

(ML) Modules vs (Haskell) Type Classes

According to Harper (https://existentialtype.wordpress.com/2011/04/16/modules-matter-most/), it seems that Type Classes simply do not offer the same level of abstraction that Modules offer and I'm having a hard time exactly figuring out why. And…
Rahul Manne
  • 1,169
  • 9
  • 19
26
votes
2 answers

Line Comments in Standard ML

I'm learning ML, with the SML/NJ dialect. What I'm trying to figure out is if there is a line comment operator. I found the block comment operator, (* ... *), but I really miss line comments. Suggestions? Or am I just stuck with block comments?
icco
  • 3,024
  • 4
  • 32
  • 46
25
votes
4 answers

Functional Breadth First Search

Functional depth first search is lovely in directed acyclic graphs. In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but let's say I can't do that. A list of visited nodes…
N. McA.
  • 4,236
  • 3
  • 32
  • 58
1
2 3
99 100