Standard ML
Standard ML (SML, Standard Meta Language - სტანდარტული მეტა ენა) არის ფართო სფეროიანი, …
| პარადიგმა | ფუნქციური, ბრძანებითი |
|---|---|
| გამოქვეყნების თარიღი | 1990, 1997 (ენის სპეციფიკაცია) |
| ტიპების განსაზღვრა | ძლიერი, სტატიკური, დასკვნის გაკეთებით |
| მთავარი ვერსიები | MLton, Standard ML of New Jersey, Moscow ML, Poly/ML, TILT, HaMLet, ML Kit, SML.NET, Poplog, SML# |
| ენების ზეგავლენით | ML |
| ენებზე ზეგავლენა | ობიექტური კამლი |
Standard ML (SML, Standard Meta Language - სტანდარტული მეტა ენა) არის ფართო სფეროიანი, ფუნქციური, ბრძანებით, მოდულარული, პროგრამირების ენა რომელშიც ცვლადების ტიპები კომპილირების დროს არიან დასკვნილი. იგი პოპულარულია კომპილატორების და პროგრამირების ენების შემქნელთა წრეებში, და აგრეთვე მათემატიკური დამტკიცებისთვის.
SML-ი არის ML პროგრამირების ენის თანამედროვე წარმომავალი. უფრო მეტად გავრცელებული პროგრამირების ენების განსხვავებით იგი დაფუძნებულია სპეციფიკაციის მიხედვით, The Definition of Standard ML (1990, განახლებული და გამარტივებული: Definition of Standard ML (Revised), 1997 წელს).
მაგალითები
ფაქტორიალი:
fun factorial 0 = 1
| factorial n = n * factorial (n-1)
დახარისხების ალგორითმი Quicksort-ი
fun quicksort << xs = let
fun qs [] = []
| qs [x] = [x]
| qs (p::xs) = let
val (less, more) = List.partition (fn x => << (x, p)) xs
in
qs less @ p :: qs more
end
in
qs xs
end
მოკლე ენის მაგალითი, დააკვირდით რა მარტივად არის შექმნილი.
exception Err
datatype ty
= IntTy
| BoolTy
datatype exp
= True
| False
| Int of int
| Not of exp
| Add of exp * exp
| If of exp * exp * exp
fun typeOf (True) = BoolTy
| typeOf (False) = BoolTy
| typeOf (Int _) = IntTy
| typeOf (Not e) = if typeOf e = BoolTy then BoolTy else raise Err
| typeOf (Add (e1, e2)) =
if (typeOf e1 = IntTy) andalso (typeOf e2 = IntTy) then IntTy else raise Err
| typeOf (If (e1, e2, e3)) =
if typeOf e1 <> BoolTy then raise Err
else if typeOf e2 <> typeOf e3 then raise Err
else typeOf e2
fun eval (True) = True
| eval (False) = False
| eval (Int n) = Int n
| eval (Not e) =
(case eval e
of True => False
| False => True
| _ => raise Fail "type-checking is broken")
| eval (Add (e1, e2)) = let
val (Int n1) = eval e1
val (Int n2) = eval e2
in
Int (n1 + n2)
end
| eval (If (e1, e2, e3)) =
if eval e1 = True then eval e2 else eval e3
fun chkEval e = (ignore (typeOf e); eval e) ''(* will raise Err on type error *)''
რესურსები ინტერნეტში
- (ინგლისური) What is SML?
- (ინგლისური) What is SML '97?
- (ინგლისური) successor ML (sML) დაარქივებული 2009-01-07 საიტზე Wayback Machine. is intended to provide a vehicle for the continued evolution of ML, using Standard ML as a starting point.
- (ინგლისური) at Scholarpedia, curated by Mads Tofte.
| ||||||||||||||
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.