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

How to 'fix' the SML/NJ interactive system to use Arrow Keys

I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last expression), my Terminal prints codes. (e.g. ^[[A…
pablo.meier
  • 2,339
  • 4
  • 21
  • 29
24
votes
1 answer

What, if anything, do you need to add to a dependent type system to get a module system?

Dependent type systems seem to support some of the uses of a ML module system. What do you get out of a module system that you do not get out of dependent records? module ~ record signature ~ record type functor ~ function on records module with an…
Jules
  • 6,318
  • 2
  • 29
  • 40
24
votes
1 answer

How can I load a ml file in toplevel of OCaml, just like `use mine.sml` in SML/NJ?

In SML's repl, you can just type use whatever.sml and load all things inside that .sml into repl. How can I do that in OCaml?
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
23
votes
2 answers

What are the limits of type inference?

What are the limits of type inference? Which type systems have no general inference algorithm?
user141335
21
votes
3 answers

Curried anonymous function in SML

I have the function below and it works: (fn x => x * 2) 2; but this one doesn't work: (fn x y => x + y ) 2 3; Can anyone tell me why? Or give me some hint to get it to work?
jjennifer
  • 1,285
  • 4
  • 12
  • 22
20
votes
7 answers

What is SML used for?

What are the uses of SML in the real word? Are its practical uses similar to that of Prolog?
CreamBun
19
votes
3 answers

Is there a Haskell/ML-like compiler to C?

People have written games for the iPhone in Scheme. Because (some) Scheme-compilers compile down to C, it was easy to mix with Objective-C and integrate with XCode. I am aware of patches for Haskell and OCaml compilers to enable ARM/iOS-backends.…
LennyStackOverflow
  • 2,228
  • 1
  • 19
  • 22
19
votes
3 answers

Nested case statements in SML

This is more of a stylistic question than anything else. Given the following piece of code: case e1 of (* datatype type_of_e1 = p1 | p2 *) p1 => case e11 of (* datatype type_of_e11 = NONE | SOME int *) …
slash3r
  • 193
  • 1
  • 7
18
votes
1 answer

How do functional languages represent algebraic data types in memory?

If you were writing a bioinformatics algorithm in Haskell, you'd probably use an algebraic data type to represent the nucleotides: data Nucleotide = A | T | C | G You'd do similarly in Standard ML or OCaml, I assume (I've never really used…
Mike
  • 1,569
  • 2
  • 14
  • 20
18
votes
3 answers

SML: difference between type and datatype

I'm pretty new at SML and I would like to make sure I really know the basics. What is the difference between type and datatype in SML, and when to use which?
Horse SMith
  • 1,003
  • 2
  • 12
  • 25
17
votes
2 answers

SML: What's the difference between using abstype and using a signature to hide the implementation of a structure?

I've done a little work in SML in the past, but I'm now starting to get to the more interesting parts. Using the abstype...with...end construct, I can make things but keep their implementation details hidden. I can also create a signature of the…
Alan
  • 171
  • 1
  • 3
17
votes
1 answer

Increasing the print depth in SML/NJ

I'm trying to get SML/NJ to print out a result at the top level without putting # signs everywhere. According to some old docs (and a post to this newsgroup on 2001), it should be possible to use Compiler.Control.Print.printDepth However, on SML/NJ…
higherDefender
  • 1,551
  • 6
  • 23
  • 35
17
votes
1 answer

When to use semicolons in SML?

I know that semicolons are used as terminators in REPL. But I'm confused about when to use them in a source file. For example it is not necessary after val x = 1. But if I omit it after use "foo.sml", the compiler will complain about it. Then, what…
Ben
  • 3,612
  • 3
  • 19
  • 24
16
votes
3 answers

Is the SML `o` operator only useful on single-argument functions?

Is the o composition operator (eg. val x = foo o bar, where foo and bar are both functions), only usable on single-argument functions and/or functions with equal numbers of arguments? If not, what is the syntax for, say, composing foo(x,y) with…
GregT
  • 1,300
  • 3
  • 16
  • 25
15
votes
3 answers

Statically "extend" a record-ish data type without indirection hassle

I am currently working with a three-level process for which I need some information to flow being accessed and updated. The information is also three-leveled, in such a way that a process at one level may need to access/update information at its…
Ptival
  • 9,167
  • 36
  • 53