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

Lexical Scope in Python vs ML

I'm in a big dilemma, take the following code written in ML: val x = 1 fun f(y) = x + y val x = 2 val y = 3 val z = f (x + y) The value of z is 6. Now if I write the same code in python the value of z would be 7. And both languages claim(actual the…
Mihai Vinaga
  • 1,059
  • 2
  • 10
  • 27
8
votes
1 answer

Passing command-line arguments to an SML script

How do I go about passing command-line arguments to an SML script? I'm aware that there is a CommandLine.arguments() function of the right type (unit -> string list), but invoking the interpreter like so: $ sml script_name.sml an_argument…
abeln
  • 3,749
  • 2
  • 22
  • 31
8
votes
3 answers

How to add readline support in polyml interpreter?

I found that polyml is the implementation of ML that can be easily installed on Ubuntu (named polyml in repository and can be executed with poly). I am following the A Gentle Introduction to ML by Andrew Cumming. After few minutes of experiment with…
Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
8
votes
4 answers

How to use AND operator in IF statements in SML

I am new to SML. How do I use the AND operator inside IF statements? Here is my code: val y = 1; val x = 2; if (x = 1 AND y = 2) then print ("YES ") else print("NO "); My error is: stdIn:66.9-67.3 Error: unbound variable or constructor:…
Alexander Tilkin
  • 149
  • 1
  • 2
  • 13
7
votes
2 answers

What Javascript libraries have good support for syntax highlighting of OCaml code?

Ideally the library supports a wide range of languages in addition to OCaml, but good support for OCaml is the main requirement.
Ashish Agarwal
  • 3,000
  • 16
  • 18
7
votes
2 answers

Function which applies its argument to itself?

Consider the following SML function: fn x => x x This produces the following error (Standard ML of New Jersey v110.72): stdIn:1.9-1.12 Error: operator is not a function [circularity] operator: 'Z in expression: x x I can sort of see why…
Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97
7
votes
2 answers

Typecasting in SML

I'm new to SML, and am using the SMLNJ dialect. For some purpose I have been trying to typecast 3 to 3.0 (int to real). Could not find a way out. How can I do this? How can I convert between types?
Dave
  • 391
  • 3
  • 5
  • 13
7
votes
1 answer

what are curry and uncurry in high-order functions in ML

fun curry f x y = f (x, y); fun uncurry f (x, y) = f x y; fun compose (f, g) x = f (g x); I understand compose function, but not quite understand curry and uncurry in ML. Can anyone explain these? Also, what do the following two lines mean? (1)…
Jensen
  • 1,653
  • 4
  • 26
  • 42
7
votes
2 answers

SML - unbound variable or constructor

I have the next code: datatype expr = K of string| Number2 of expr * (expr list); datatype number = Number1 of string | Number3 of int; fun append (nil, l2) = l2 | append (x::xs, l2) = x::append(xs, l2); fun map [] = [] | map (h::t) =…
Adam Sh
  • 8,137
  • 22
  • 60
  • 75
7
votes
3 answers

Case Statements and Pattern Matching

I'm coding in SML for an assignment and I've done a few practice problems and I feel like I'm missing something- I feel like I'm using too many case statements. Here's what I'm doing and the problem statements for what I'm having trouble…
user998876
  • 167
  • 1
  • 1
  • 7
7
votes
2 answers

How can I print polymorphic values in Standard ML?

Is there a way to print polymorphic values in Standard ML (SML/NJ specifically)? I have a polymorphic function that is not doing what I want and due to the abysmal state that is debugging in SML (see Any real world experience debugging a production…
Andrew Keeton
  • 22,195
  • 6
  • 45
  • 72
7
votes
1 answer

Why is exporting fixity declarations a "bad idea"?

According to David MacQueen in his Reflections on Standard ML report1, Lexically-scoped infix directives were an ill-advised legacy from Pop-2. They complicate parsing and they do not work well with the module system because infix directives cannot…
Moth
  • 253
  • 2
  • 8
7
votes
1 answer

use operation in sml (where is current directory smlnj windows)

I have never used SML on a Windows machine (have before on a unix machine w/ emacs). for the life of me I cannot find the current directory when in the sml environment. If I attempt to: use "filename.sml" it raising an exception.. I cannot find…
DJPlayer
  • 3,244
  • 2
  • 33
  • 40
7
votes
1 answer

Applicative vs Generative functors

I have recently been learning SML, when I came to know the terms - applicative and generative functors. I also know that SML uses generative functors. I tried to Google the terms but couldn't find any compelling resources that explains what these…
him
  • 487
  • 3
  • 12
7
votes
1 answer

How to import from another file in SML, with a path relative to the importer?

I'm using SML/NJ, and I need to use a set of functions that are in a certain file f1.sml inside another file f2.sml. However, I'm not running f2.sml directly, rather, I'm importing it from somewhere else. If I use the use command in f2.sml with the…
leolovesai
  • 73
  • 3