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
14
votes
1 answer

Why SML and OCaml are considered as dialects of ML? What is the definition of ML?

There are many dialects of ML, and SML and OCaml are most popular ones. There're many differences between SML and OCaml, but they are both considered as dialects of ML. So, Why SML and OCaml are considered as dialects of ML? How can a language be…
InsaneRabbit
  • 186
  • 7
13
votes
1 answer

How to convert negative integers to strings in SML with minus sign instead of tilde?

The standard SML library function Int.toString prefixes negative numbers with ~ instead of -. Is there a library function to use - instead, short of writing fun i2s i = if i < 0 then "-" ^ Int.toString (~i) else Int.toString i
Jay Lieske
  • 4,398
  • 3
  • 25
  • 41
12
votes
1 answer

Pattern match in binding of lambda?

In Haskell, I often do something like this: f $ \x -> case x of A a1 a2 -> ... B b1 b2 -> ... C c1 c2 -> ... But I don't want x, I just want to deconstruct it. In Standard ML I can do something like this: f (fn…
og_loc
  • 173
  • 3
12
votes
1 answer

Understanding foldl in ML

I need to write a function that takes a list of strings and finds the largest string in the list. The catch is it needs to iterate through the list using List.foldl and cannot use recursive calls except for those in the library function of…
12
votes
2 answers

Does Standard ML support Unicode?

Does Standard ML support Unicode? I believe it does not but cannot find any authoritative documentation for SML stating such. A yes or no is all that is needed, but you must know for a fact. No guessing or I believe answers. An authoritative link…
Guy Coder
  • 22,011
  • 6
  • 54
  • 113
11
votes
1 answer

How do you print inside a case statement in SML?

I'm just starting out with SML, and I'm trying to modify some code so I understand what it's doing (I can't find a decent SML/NJ debugger, but that's a separate question). fun type_check e theta env non_gens = case e of constant_int _ =>…
Kai
  • 3,897
  • 4
  • 28
  • 35
11
votes
2 answers

Difference between "local" and "let" in SML

I couldn't find a beginner friendly answer to what the difference between the "local" and "let" keywords in SML is. Could someone provide a simple example please and explain when one is used over the other?
Johan
  • 703
  • 1
  • 11
  • 24
11
votes
3 answers

Do OCaml 'underscore types' (e.g. '_a) introduce the possibility of runtime type errors / soundness violations?

I was reading a little bit about the value restriction in Standard ML and tried translating the example to OCaml to see what it would do. It seems like OCaml produces these types in contexts where SML would reject a program due to the value…
Gregory Nisbet
  • 5,950
  • 3
  • 21
  • 50
11
votes
1 answer

What is the difference in capability between the SML module system and Haskell's Type and Typeclass system?

I'm trying to understand where the shortcoming is here. Does the SML Module system merely provide dependent types, similar to how Idris has extended the Haskell type system, or is there more going on than just the addition capability of dependent…
josiah
  • 1,216
  • 1
  • 10
  • 27
11
votes
1 answer

SML Warning: Type Vars Not Generalized when using Empty Lists or NONE option

I can't for the life of me figure out why the following SML function is throwing a Warning in my homework problem: fun my_func f ls = case ls of [] => raise MyException | head :: rest => case f head of SOME v => v …
mbear
  • 111
  • 1
  • 6
11
votes
5 answers

Standard sorting functions in SML?

Are there standard sorting functions in SML? The documentation on the Internet is so scarce I couldn't find any.
Alexei Averchenko
  • 1,556
  • 12
  • 27
10
votes
2 answers

Evaluate buffer in ghci or hugs via Emacs

Using sml-mode in Emacs I have been able to send my buffer contents directly to an inferior SML process using C-c C-b. Now I want to do the same thing only with Haskell. Haskell-mode does not seem to support this, so I'm wondering: What is the right…
Sarah
  • 6,374
  • 30
  • 44
10
votes
4 answers

Recursive anonymous functions in SML

Is it possible to write recursive anonymous functions in SML? I know I could just use the fun syntax, but I'm curious. I have written, as an example of what I want: val fact = fn n => case n of 0 => 1 | x => x *…
dbmikus
  • 3,921
  • 6
  • 26
  • 36
10
votes
2 answers

Problem running smlnj under OSX 10.6

I downloaded and installed the SML NJ implementation using the DMG for x86 from here : http://smlnj.cs.uchicago.edu/dist/working/110.72/index.html However when I open a terminal window and go to /usr/local/smlnj-110.72/bin and run sml i get a bash…
user671382
  • 101
  • 1
  • 3
10
votes
1 answer

Output is truncated with #-signs in the REPL

I wrote a function which works as expected but i don't understand why the output is like that. Function: datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop; (* XOR = (A And Not B) OR (Not A Or B) *) local fun…
tech-ref
  • 249
  • 1
  • 2
  • 7