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

Custom comparator sort in SML?

I am a bit stuck with this problem in SML / SMLNJ and I would love some guidance. So I have a problem where I need to make a function called insertSorted, where it takes a number, a comparison statement, and an (assumed sorted) list that it needs to…
0
votes
0 answers

What is datatype binding?

I am going through "Programming Languages" in coursera. I am having a hard time to understand what "datatype bindings" are. https://www.coursera.org/lecture/programming-languages/datatype-bindings-vysQv Are datatype bindings similar to type alias(in…
Surya
  • 2,429
  • 1
  • 21
  • 42
0
votes
2 answers

How to get out of this infinite loop in SML

Here is what my code looks like now. I'm trying to make a multi choice question program It's quite rudimentary as a way of proceeding but I find it difficult to structure the code in a more "professional" way. fun readlist(filename) = let …
0
votes
1 answer

How can i get a random line from a text file in sml ? How to make a multi choice question program in sml?

I want to make a multi choice question program in SML. I have a text file whose content is structured as follows: category1:Basic sml/sql 1-How many subsets does the power set of an empty set have? A) One B) Two C) Three D) Zero Ans:A 2-What is the…
0
votes
0 answers

Remove elements and lists in list list in SML

So I have this datatype implemented datatype 'a expression = Not of 'a expression | Or of 'a expression list | And of 'a expression list | Equality of 'a expression list | Impication of…
TenebrisNocte
  • 179
  • 10
0
votes
1 answer

getting ''a type instead of 'a in sml

I've written a hash-table for an sml assignment. I've made a polymorphic builder for the hashtable but when I use the insert function I created, I get a comparable type (''a instead of 'a) although i'm not making any comparisons that include the…
0
votes
1 answer

Connecting all elements in list with infix operator

So I have a list lets say [t, f, f, t, f] and an infix operator <==>. I want to connect the elements so the end result will look like this t <==> f <==> f <==> t <==> f . The problem that I am having though is that i get this result t <==> (f <==>…
TenebrisNocte
  • 179
  • 10
0
votes
2 answers

SML using reduce and map to traverse an n-ary tree

I'm new to SML. Say I have the following datatype: datatype 'a tree = leaf of 'a | node of 'a tree list and the function val leaves = fn : 'a tree -> 'a list: fun leaves (leaf x) = [x] | leaves (node []) = [] | leaves (node [x]) = leaves x |…
Humber
  • 5
  • 2
0
votes
1 answer

SML Traverse an N-ary tree

I'm a newbie to SML. After a couple of searches, I still can't find any resource related to traversing an n-ary tree. Many examples are just traversing a simple binary tree. Say, I have datatype 'a tree = leaf of 'a list | node of 'a tree list I…
Humber
  • 5
  • 2
0
votes
1 answer

ML - datatype and functions

We have the next dayatype: datatype complex = Rec of real * real | Polar of real * real; and two functions: - val real = fn (Rec(x,y) ) => x | (Polar(r,a)) => r * Math.cos(a); val real = fn : complex -> real - val imaginary = fn (Rec(x,y) ) =>…
Tom
  • 673
  • 4
  • 12
  • 20
0
votes
1 answer

How to iterate through a pattern and returns a list of all the strings

Hello i am currently doing the course Programing languages and am having difficulties with the following helper function: The function takes a pattern and returns a list of all the strings it uses for variables. This is the pattern: datatype…
Emil
  • 7
  • 3
0
votes
0 answers

Why am I getting these errors in my sml code?

I'm creating an interpreter in Standard ML for Standard ML for an assignment but I can't seem to get past this problem. I have this conditional in a function eval: | eval (rho, SetExp (name, value)) = (case rhoContains rho name of true …
Grav
  • 461
  • 6
  • 18
0
votes
1 answer

Can someone help me to translate this function into sml?

I've tried to translate this OCaml code type bool_expr = | Var of string | Not of bool_expr | And of bool_expr * bool_expr | Or of bool_expr * bool_expr; let rec eval val_vars = function | Var x -> List.assoc x val_vars |…
0
votes
1 answer

Return a list of all the even elements in the orginal list - how can I write this function without using recursion?

This function takes a list and returns a list of all the even elements from the original list. I'm trying to figure out how to do this using foldl, foldr, or map instead but I can't seem to figure it out. fun evens [] = [] | evens (x::xs) = …
jl8n
  • 53
  • 6
0
votes
2 answers

Why can't I call simplify around my addAll function?

I am doing this assignment for homework and I've been stuck on this problem for like 3 hours. I just emailed the professor, but haven't heard back from them yet, so I decided to ask here as well. We are assigned to write various functions, such as…
Josh K
  • 13
  • 2