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

Implementing binary search but can't find an element

I have a code in sml of binary search , the thing is when I search 20, output shows there is no element in an array even though array has 20. I can't figure out why is this happening. open Array; fun binsearch (A, x) = let val n = length…
Aniket Saxena
  • 43
  • 1
  • 6
0
votes
1 answer

Using a particular higher-order helper function to compute factorial

I'm taking a MOOC (no credit). One of the assigned problems is to write a factorial function using a function that follows this: (’a->’a)->(’a->bool)->’a->’a I've created that function: fun do_until (f, g) = fn x => case g(f x) of …
poopsmith
  • 21
  • 1
  • 3
0
votes
1 answer

Is there a Trie implementation in sml using numbers?

Is there a trie implementation in sml that takes a number from input , then breaks up the number to its digits and inserts them in the trie? Is it an already developed structure or is there some already existing code which I could use? Does it have…
user11584054
0
votes
1 answer

How to evaluate datatype and true_of_all_constants functions?

I am a beginner of sml and I'm taking programming language courses at Coursera. There's a datatype and function that I don't know how to evaluate: datatype exp = constant of int | Negate of exp |Add of exp * exp |Multiply of exp *…
0
votes
0 answers

I am trying to make a trie that each node has weight equal to its children number

I need to make a trie to calculate the winning prize of lottery tickets with a fixed function. For the function I need to know how many children each node has. First I need to create the trie and then search it to find how many tickets won. Note…
0
votes
2 answers

number_in_month exercise (SML recursive function on list interation)

I found this code on another SO post: fun number_in_month ([], _) = 0 | number_in_month ((_,x2,_) :: xs, m) = if x2 = m then 1 + number_in_month(xs, m) else number_in_month(xs, m) and to my surprise it works. - number_in_month…
147pm
  • 2,137
  • 18
  • 28
0
votes
2 answers

Implementing Yahtzee in SML

I'm writing an SML Yahtzee/Poker Program that receives a list as an input in the format yahtzee(1,3,3,4,3) in which each number is a result of a dice roll, and then prints the corresponding result, which in this case would be (three-of-a-kind,…
0
votes
2 answers

Error when trying to use or in if else statement

I am trying to write a function cardcolor with or inside an if else statement using sml as shown below datatype suit = Clubs | Diamonds | Hearts | Spades; datatype rank = Jack | Queen | King | Ace | Num of int; type card = suit * rank; datatype…
Kent Wong
  • 143
  • 8
0
votes
2 answers

Pattern matching conflict

I am having a problem with pattern matching in an sml program.My code is this: fun ff (arr, _, [], _) = [] |ff (arr, 0, (x::xs), ping_list) =ping_list |ff (arr, K, (x :: xs), ping_list) = (if Array.sub(arr, x)-1 < 1 then…
user11375639
0
votes
2 answers

Shorter way for tuple elements retargeting in SML

Currently, I use something like this in one of my functions: (all variables are used with more complex functions, but for what I will be asking it doesn't matter and I simplify) fun RecursiveCall (p, q, r, s) = let val (ra, rb, rc) =…
user3967841
0
votes
1 answer

Problem with the use of Binary Map Data Structure in SML

I want to create an ordered map with multiples nodes in SML . All i have found until now , exist here : https://www.smlnj.org/doc/smlnj-lib/Manual/binary-map-fn.html . So , i am trying something like this : structure S = BinaryMapFn(struct type…
Stelios Dr
  • 115
  • 6
0
votes
1 answer

Smallest sub-list that contains all numbers

I am trying to write a program in sml that takes in the length of a list, the max number that will appear on the list and the list of course. It then calculates the length of the smallest "sub-list" that contains all numbers. I have tried to use…
user7475343
0
votes
1 answer

How can I make a function that takes two lists as args and returns true if the first list exists in the second?

I have to write this in sml/nj I made a try and this is what I did: I want the all function to return a positive number when I run the function but for example when I give [1,2,3] [1,1,2,3,1,2,3,1] it returns nonexhaustive match failure. What is…
billyntua
  • 1
  • 2
0
votes
1 answer

Updating a variable inside a function

I have created a function in SML that traverses the starting elements of a list and if first,second,third.. element are the same deletes these elements and updates a variable's value.What i have written: let val min=7 in fun seen2…
user10971030
0
votes
1 answer

Issue in sorting SML list

I am new to SML.I got this sorting algo to implement where in each iteration,I have to pick minimum element from the list, remove it and create sorted list. I did below coding to solve the problem. I wrote 2 helper functions to pickup minimum…
Sri
  • 99
  • 10
1 2 3
99
100