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

How to print variable in sml?

I'm new to SML and in debugging I usually print out the variable to see if it matches up to what I expected it should be. I would like to print out a variable within a function what i have is this : function header.. let val prod val prod = c + x…
user4348719
  • 351
  • 1
  • 2
  • 13
9
votes
2 answers

What are the options SOME and NONE in SML?

I am new to SML (and programming, actually). fun readlist (infile : string) = let val ins = TextIO.openIn infile fun loop ins = case TextIO.inputLine ins of SOME line => line :: loop ins | NONE => []…
Rohan
  • 93
  • 1
  • 1
  • 4
9
votes
8 answers

How do I install a working version of Standard ML on Mac?

I'm using Mac OSX 10.7.5 and I can't seem to get download a working Standard ML compiler with a REPL available. Is this supposed to be so difficult? Is there a best ML that I should be downloading. I've tried SML/NJ and MLton to no avail.
ordinary
  • 5,943
  • 14
  • 43
  • 60
9
votes
5 answers

How to use List.filter?

I have this code to filter list of string that the first letter is capital: fun f s = Char.isUpper(String.sub(s,0)); fun only_capitals (xs : string list) = List.filter(f , xs); But when compile, I always receive error : operator domain: 'Z ->…
hqt
  • 29,632
  • 51
  • 171
  • 250
9
votes
2 answers

Does Scala have a statement equivalent to ML's "as" construct?

In ML, one can assign names for each element of a matched pattern: fun findPair n nil = NONE | findPair n (head as (n1, _))::rest = if n = n1 then (SOME head) else (findPair n rest) In this code, I defined an alias for the first pair of the…
Evan Kroske
  • 4,506
  • 12
  • 40
  • 59
8
votes
2 answers

what does Cons do in this function?

I'm confused as to what the Cons() function does, in the function definition for from.
jfisk
  • 6,125
  • 20
  • 77
  • 113
8
votes
3 answers

Learning/using ML. Which system should i use?

I want to learn and use ML but there are many compilers out there. I need: speed low memory usage threading mutable arrays and record types continuations ready for production code easy ffi up to date ... helpful libraries portable to some degree I…
knivil
  • 916
  • 5
  • 10
8
votes
3 answers

Expanding # in sml

Suppose I have a list in sml which is very big then sml shows a few of the entries and then starts showing # character. Could someone tell me how could I view the whole list?
noddy
  • 1,010
  • 4
  • 14
  • 27
8
votes
1 answer

Compiling SML projects from multiple files

I've got a project with many files in it and I want it to work with most popular compilers. Unfortunately, PolyML and SML/NJ require use statements, while MosML additionally requires explicitly loading basis library structures using load, which is…
zlotnleo
  • 275
  • 2
  • 12
8
votes
2 answers

SML: How to append an element to a list in SML?

Is there an operator in SML which allows me to append to a list without having to create a new list? For example I cant do this: [1,2,3]::1 but I can do this: [1,2,3]@[1] which is odd as I have to create a list with 1 in it. Is there a better…
Har
  • 3,727
  • 10
  • 41
  • 75
8
votes
1 answer

How to decide whether to parameterize on the type-level or the module-level when designing modules?

I'm working towards a deep understanding of ML-style modules: I think the concept is important and I love the kind of thinking they encourage. I am just now discovering the tension that can arise between parametric types and parametric modules. I am…
Shon
  • 3,989
  • 1
  • 22
  • 35
8
votes
3 answers

Multiple Patterns in 1 case

In SML, is it possible for you to have multiple patterns in one case statement? For example, I have 4 arithmetic operators express in string, "+", "-", "*", "/" and I want to print "PLUS MINUS" of it is "+" or "-" and "MULT DIV" if it is "*" or…
rlhh
  • 893
  • 3
  • 17
  • 32
8
votes
3 answers

Fast Standard ML compiler or bytecode interpreter, with read-eval-print loop, for Linux?

For use with a class I'll be teaching, I'm looking for a fast compiler or bytecode interpreter for Standard ML. I'm looking for fast compile times; any reasonable run time will do. Bonus if the compilation model is simple and clear. Students in…
Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
8
votes
2 answers

Do ML family compilers do any sophisticated optimization for tail calls?

I (believe) the following function definition is tail-recursive: fun is_sorted [] = true | is_sorted [x] = true | is_sorted (x::(y::xs)) = if x > y then false else is_sorted (y::xs) Trivially, it's equivalent to the following…
Zach Halle
  • 321
  • 1
  • 9
8
votes
4 answers

Remove duplicates from a list in SML

I just started learning functional programming in SML and I want to know how I can combine the following two functions into a single function. The function isolate deletes the duplicates of a list of any type ('a) using the helper function…
macalaca
  • 988
  • 1
  • 13
  • 31