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
11
votes
3 answers

Run SML file but not be left in interactive mode

I am using New Jersey SML on Windows. If test.sml is an SML file I can execute it by running this at a Windows command prompt: C:\> sml test.sml I then get the usual SML output and a new SML command prompt. Standard ML of New Jersey v110.75…
rlandster
  • 7,294
  • 14
  • 58
  • 96
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,706
  • 1
  • 16
  • 29
11
votes
3 answers

Standard ML functor examples

Functors in Standard ML are related to the module system and can generate structures based on other structures. An example of a functor generating list combinators for various types of lists is given below, but this example has a problem: The…
sshine
  • 15,635
  • 1
  • 41
  • 66
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,565
  • 1
  • 33
  • 44
10
votes
2 answers

How to import code in SML?

I'm currently grading assignments for a course on SML. I've written some test cases to automatically check correctness of functions in the students' assignments, and I'd like to be able to import their code and then run the test cases against that…
jbeard4
  • 12,664
  • 4
  • 57
  • 67
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
  • 269
  • 1
  • 2
  • 9
10
votes
2 answers

SML How to check variable type?

Is there any way to check/test the type of a variable? I want to use it like this: if x = int then foo else if x = real then bar else if x = string then ... else .....
TBK
  • 129
  • 1
  • 2
  • 8
10
votes
1 answer

how do I add a line break in a string?

The question is in the title. If I do this in the REPL (SML/NJ in windows commandline) val x = "hello\nworld"; I'd expect val x = "hello world" : string or something similar, but I get val x = "hello\nworld" : string although I found somewhere…
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
10
votes
3 answers

How to convert anything to string, in SML?

I'm trying to implement a test function to compare and show error message if they are not equal: exception AssertionErrorException of string fun assert(testName, actual, expect) : bool = if actual = expect then true else raise…
Freewind
  • 193,756
  • 157
  • 432
  • 708
10
votes
3 answers

GUI for Standard ML?

I started learning Standard ML recently out of curiosity. So what I know is that is has an efficient compiler (MLton) which allows us to freely use abstractions without worrying about performance. It would be perfect if I could do some GUI…
Phil
  • 5,595
  • 5
  • 35
  • 55
10
votes
3 answers

How can I easily write simple tactics at the ML level of Isabelle?

In an Isabelle theory file, I can write simple one-line tactics such as the following: apply (clarsimp simp: split_def split: prod.splits) I find, however, when I start writing ML code to automate proofs, to produce an ML tactic object, these…
davidg
  • 5,868
  • 2
  • 33
  • 51
10
votes
3 answers

Accessing SML tuples by Index Variable

Question is simple. How to access a tuple by using Index variable in SML? val index = 5; val tuple1 = (1,2,3,4,5,6,7,8,9,10); val correctValue = #index tuple1 ?? I hope, somebody would be able to help out. Thanks in advance!
InnovWelt
  • 660
  • 1
  • 8
  • 21
10
votes
3 answers

Suppress "val it" output in Standard ML

I'm writing a "script" in Standard ML (SML/NJ) that sets up the interactive environment to my liking. The last thing the script does is print out a message indicating everything went smoothly. Essentially, the last line is this: print "SML is…
Barry Brown
  • 20,233
  • 15
  • 69
  • 105
9
votes
0 answers

Which languages, if any, implement rank-2 parametric polymorphism and why not ML?

In section 23.8 of his book Types and Programming Languages, Benjamin C. Pierce writes the following: Another well-studied restriction of System F is rank-2 polymorphism, introduced by Leivant (1983) [...]. A type is said to be of rank 2 if no path…
authchir
  • 1,605
  • 14
  • 26
9
votes
1 answer

'How to use higher order functors properly?' or 'How to have serious fun with funsigs?'

Motivation For the life of me, I cannot figure out how to use higher order functors in SML/NJ to any practical end. According to the SML/NJ docs on the implementation's special features, it should be possible to specify one functor as an argument…
Shon
  • 3,989
  • 1
  • 22
  • 35