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

ANTLR4 grammar for SML choking on positive integer literals

I'm building a parser for SML using ANTLR 4.8, and for some reason the generated parser keeps choking on integer literals: # CLASSPATH=bin ./scripts/grun SML expression -tree <<<'1' line 1:0 mismatched input '1' expecting {'(', 'let', 'op', '{',…
D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
0
votes
1 answer

Ml syntax error, how to verify code error?

I'm a newby. I write below code. Delay(e) == fn () => e Force(e) == e() fun time_consuming(n) = let fun tak(x, y, z) = if x <= y then y else tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y)) in fun tak(3*n, 2*n,…
manut
  • 113
  • 1
  • 2
  • 7
0
votes
1 answer

SMLNJ function that returns as a pair a string at the beginning of a list

So im really confused as i am new to sml and I am having trouble with syntax of how i want to create my function. the instructions are as follows... numberPrefix: char list → string * char list Write a function named numberPrefix that returns (as a…
mgherghi
  • 9
  • 2
0
votes
1 answer

How to read string from user keyboard in SML language?

I am new to the SML language and I want to do this: to ask a person "what is your full name?" to get answer from user's keyboard and to write "your full name is"+name (his or her name that answered)
0
votes
1 answer

ml datatype (with primitive functions) how to make?

i have this datatype datatype e = X | Const of int | P of e*e | S of e*e | M of e*e | D of e*e; and this procedure val rec evl = fn (Const k)=>(fn x=>k)| X=> (fn x=>x)| P(e1,e2)=> (fn x=> (evl e1 x)+(evl e2 x))| S(e1,e2)=> (fn x=> (evl e1 x)-(evl…
aseed
  • 110
  • 13
0
votes
1 answer

How to make this ml procedure

I have this code: datatype 'a tree = Leaf of 'a | Node of 'a * 'a tree * 'a tree | Nil; val rec tree_sum = fn(f,e,Nil) => e | (f,e,Leaf(n)) => n | (f,e,Node(node,right,left)) => …
aseed
  • 110
  • 13
0
votes
1 answer

SML datatype match redundant produces redundancy

I have this from The Little MLer datatype 'a pizza = Bottom | Topping of ('a * ('a pizza)) and this datatype fish = Anchovy | Lox | Tuna and this working code fun rem_fish (f, fp) = let fun…
147pm
  • 2,137
  • 18
  • 28
0
votes
2 answers

list in SML Language

I'm new to SML and I'm trying to run some code from github in SML/NJ. I'm currently trying to call the function fun dates_in_month(xs : (int * int * int) list, n : int) = if null xs then [] else if #2 (hd xs) = n then (hd…
0
votes
1 answer

SML datatype casting: binding not exhaustive

I have this "shape" as The Little MLer calls it datatype 'a pizza = Bottom | Topping of ('a * ('a pizza)) and this datatype fish = Anchovy | Lox | Tuna and here is an object of this datatype Topping…
147pm
  • 2,137
  • 18
  • 28
0
votes
1 answer

SML how to change String after isSubstring comparison

I am currently learning SML/NJ due to a program that uses mostly a gui for basic input, but SML input for advanced options. I want to compare whether one string is a substring of another. If the condition is true then the full string should…
ryan_93
  • 1
  • 1
0
votes
1 answer

Is a structure declaration a declaration in the core language or the module language?

In SML's grammar Core Language dec ::= val ⟨var⟩(,) valbind value fun ⟨var⟩(,) funbind function type typbind type datatype datbind ⟨withtype typbind⟩ data type datatype id = datatype longid data type…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
1 answer

How are declarations in a SML program separated?

In SML's grammar Programs prog ::= dec core declaration functor fctbind functor declaration signature sigbind signature declaration empty prog1 ⟨;⟩ prog2 sequence fctbind ::= id1 ( id2 : sig ) ⟨:⟨>⟩…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
2 answers

What kinds of declarations does an environment in SML consist of?

In SML, an environment consists of bindings of variables and their denoted values. Does an environment consist of bindings of which of the following declarations? val declarations function declarations type declarations datatype…
Tim
  • 1
  • 141
  • 372
  • 590
0
votes
1 answer

SML - operator and operand disagree

I have this simple function: val CLC_seq= fn (n) => (Cons (n, find_CLC_seq(COL_seq(n)))) When: find_CLC_sqe is : int seq -> int; COL_seq is: fn: int -> int seq; The complier wrote: Error: operator and operand don't agree operator…
Tom
  • 673
  • 4
  • 12
  • 20
0
votes
2 answers

Why are the concatenation operator @ or arithmetic operators not legal pattern constructors?

In Ullman's SML book There are some other patterns that make sense but are illegal in ML. For example, we might expect to be able to construct patterns using the concatenation operator @ or arithmetic operators. Example 3.20: We might expect…
Tim
  • 1
  • 141
  • 372
  • 590