JDT

 

FREE Downloads
Articles
Tutorials

 

SML (Standard ML)


Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference.

It is popular among compiler writers and programming language researchers, as well as in the development of theorem provers.

SML is a modern descendant of the ML programming language used in the Logic for Computable Functions (LCF) theorem-proving project.

It is distinctive among widely used languages in that it has a formal specification, given as typing rules and operational semantics in The Definition of Standard ML (Revised) in 1997).

Language

Standard ML is a mostly functional programming language. Programs written in Standard ML mostly consist of expressions whose values are to be calculated.

Like all functional programming languages, a key feature of Standard ML is the function, which is used for abstraction. For instance, the factorial function can be expressed as:

   fun factorial n =
       if n = 0 then 1 else n * factorial (n-1)

A Standard ML compiler is required to infer the static type int -> int of this function without user-supplied type annotations. I.e., it has to deduce that n is only used with integer expressions, and must therefore itself be an integer, and that all value-producing expressions within the function return integers.

The same function can be expressed with clausal function definitions where the if-then-else conditional is replaced by a sequence of templates of the factorial function evaluated for specific values, separated by '|', which are tried one by one in the order written until a match is found:

   fun factorial 0 = 1
     | factorial n = n * factorial (n - 1)

This can be rewritten using a case statement like this:

   val rec factorial =
       fn n => case n of 0 => 1
                       | n => n * factorial (n - 1)

Here, the keyword val introduces a binding of an identifier to a value, fn introduces the definition of an anonymous function, and case introduces a sequence of patterns and corresponding expressions.

Using a local function, this function can be rewritten to use tail recursion:

   fun factorial n =
       let
           fun tail_fact p 0 = p
             | tail_fact p m = tail_fact (p * m) (m - 1)
       in
           tail_fact 1 n
       end

The value of a let-expression is that of the expression between in and end.



Article source: http://en.wikipedia.org/wiki/SML_(programming_language)






Go back to Articles home page

Go back to Programming Articles home page



Earnings Tracker is John Dixon Technology's FREE open source accounting and bookkeeping software tool.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker is aimed at contractors and freelancers, and lets you record invoice amounts, salaries, income tax, pension contributions, employers and employees national insurance contributions, and calculates the amount of VAT and corporation /business tax due, and the size of dividends that can be taken by shareholders.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions