Standard-ML

Standard-ML

Standard ML (SML) ist eine von ML abstammende funktionale Programmiersprache mit einigen imperativen Merkmalen (zum Beispiel im Bereich File IO).

ML-Schöpfer Robin Milner schlug SML 1983 vor, um die verschiedenen Dialekte von ML zu standardisieren. Die Sprache wurde von 1984 bis 1988 entwickelt und schließlich 1990 von Robin Milner, Mads Tofte und Robert Harper formalisiert. 1997 wurde mit SML'97 eine Revision der Sprache veröffentlicht, die neben einigen Vereinfachungen auch eine SML-Basisbibliothek enthält.

Wichtige Merkmale von SML sind unter anderem die statische Typisierung, Polymorphie auf Funktions- und Datentypsebene, automatische Speicherbereinigung sowie strenge Auswertung und Ausnahmebehandlung. Außerdem unterstützt SML Funktionen höherer Ordnung, Module und sogenannten Funktoren, die hier parametrisierte Datentypen bezeichnen.

Eine Besonderheit von SML ist, dass die Sprache vollständig formal definiert ist. Dadurch können wichtige Eigenschaften der Sprache mathematisch bewiesen werden.

Inhaltsverzeichnis

Programmbeispiele

Rekursive Berechnung der Fakultät

Die Fakultät einer natürlichen Zahl kann man in SML mittels folgendes Programmes berechnen:

fun fak (n) = if n < 1 then 1 else n * fak (n-1)

Rekursive Berechnung der Fibonacci Zahlen

Die n-te Fibonacci-Zahl kann man in SML mittels folgenden Programms berechnen:

fun fib (n) = if n < 2 then 1 else fib(n-1) + fib(n-2)

Die Stelligkeit einer Zahl

fun stell (x:int) = if x<1 then 0 else stell(x div 10) + 1

Die Quersumme einer Zahl

fun quer (x:int) = if x<1 then 0 else quer(x div 10) + x mod 10

Die Faltungsprozedur foldl für Listen

fun foldl f s nil = s
| foldl f s (x::xr) = foldl f (f(x,s)) xr

Das Umwandeln eines Strings, der eine Zahl darstellt, zu Int

fun toInt x = foldl(fn(i,k)=>ord(i)-ord #"0" + k*10) 0 (explode x)

Insertsort

fun insert (x, nil) = [x]
| insert (x, y::yr) = if x<=y then x::y::yr else y::insert(x,yr)
fun isort xs = foldl insert nil xs

Mergesort

fun split xs = foldl (fn(i, (ys,zs)) =>(zs, i::ys)) (nil,nil) xs
fun merge (xs,nil) = xs
| merge (nil,ys) = ys
| merge (x::xr,y::yr) = if x<=y then x::merge(xr,y::yr) else y::merge(x::xr,yr)
fun mergesort nil = nil
| mergesort [x] = [x]
| mergesort xs = let val (ys,zs) = split(xs) in merge(mergesort ys, mergesort zs) end


Weblinks

Es existieren verschiedene Compiler für SML, die entweder Bytecode oder Maschinencode generieren. Die Referenzimplementierung ist SML/NJ. Sml2c ist ein besonderer Compiler, der SML in C Code übersetzt.

Literatur

  • Robin Milner, Mads Tofte, Robert Harper, D. MacQueen: The Definition of Standard ML (Revised). MIT Press, 1997, ISBN 0262631814 (offizielle Sprachdefinition). 
  • Gert Smolka, “Programmierung - eine Einführung in die Informatik mit Standard ML”, 2008. München, Oldenbourg Wissenschaftsverlag, ISBN 978-3-486-58601-5

Wikimedia Foundation.

Игры ⚽ Нужен реферат?

Schlagen Sie auch in anderen Wörterbüchern nach:

  • Standard... — Standard …   Deutsch Wörterbuch

  • Standard- — Standard …   Deutsch Wörterbuch

  • Standard A.C. — Standard Athletic Club Pour les articles homonymes, voir Standard. Standard A.C …   Wikipédia en Français

  • Standard AC — Standard Athletic Club Pour les articles homonymes, voir Standard. Standard A.C …   Wikipédia en Français

  • Standard J — Role Trainer National origin USA Manufacturer …   Wikipedia

  • standard — STÁNDARD, standarde, s.n. 1. Normă sau ansamblu de norme care reglementează calitatea, caracteristicile (caracteristic), forma etc. unui produs; document în care sunt consemnate (consemna) aceste norme. ♦ (concr.) Produs realizat pe baza unui… …   Dicționar Român

  • Standard — Stand ard, a. 1. Being, affording, or according with, a standard for comparison and judgment; as, standard time; standard weights and measures; a standard authority as to nautical terms; standard gold or silver. [1913 Webster] 2. Hence: Having a… …   The Collaborative International Dictionary of English

  • standard — [stan′dərd] n. [ME < OFr estendard < Frank * standord, place of formation < Gmc * standan, to STAND + * ort, a place, orig., a point, akin to OE ord (see ODD): hence, orig., a standing place] 1. any figure or object, esp. a flag or… …   English World dictionary

  • Standard — Stand ard ( [ e]rd), n. [OF. estendart, F. [ e]tendard, probably fr. L. extendere to spread out, extend, but influenced by E. stand. See {Extend}.] 1. A flag; colors; a banner; especially, a national or other ensign. [1913 Webster] His armies, in …   The Collaborative International Dictionary of English

  • Standard e-1 — Constructeur …   Wikipédia en Français

  • standard — stan·dard n 1: something established by authority, custom, or general consent as a model, example, or point of reference the standard of the reasonable person 2: something established by authority as a rule for the measure of quantity, weight,… …   Law dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”