1 / 12

Standard ML of New Jersey

Standard ML of New Jersey. Li-Wen Hsu <lwhsu@csie.nctu.edu.tw>. Standard ML of New Jersey. Compiler and programming environment for the Standard ML programming language. http://www.smlnj.org/ Download http://www.smlnj.org/dist/working/ 110.59 110. 60 Standard ML of NJ User's Guide

helen
Download Presentation

Standard ML of New Jersey

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Standard ML of New Jersey Li-Wen Hsu <lwhsu@csie.nctu.edu.tw>

  2. Standard ML of New Jersey • Compiler and programming environment for the Standard ML programming language. • http://www.smlnj.org/ • Download • http://www.smlnj.org/dist/working/ • 110.59 • 110.60 • Standard ML of NJ User's Guide • http://www.smlnj.org/doc/index.html

  3. Connect to Workstation • PuTTY • http://www.chiark.greenend.org.uk/~sgtatham/putty • Workstations • bsd1.cs.nctu.edu.tw • bsd2.cs.nctu.edu.tw • linux1.cs.nctu.edu.tw

  4. Standard ML of New Jersey Interactive System • $ sml • http://www.smlnj.org/doc/interact.html

  5. factorial.sml fun factorial(0) = 1 | factorial(n:int) = n * factorial(n-1);

  6. fib.sml fun fib(n) = if n < 2 then 1 else fib(n-1)+fib(n-2);

  7. Base Types • int • Values: 3, ~2, 9999, ... • Operations: +,-,*,/, mod, div, =, <, ... • real • Values: 3.14, ~2.17, 0.1E6, ... • Operations: +,-, *,/, =, <, ... • char • Values: #"a", #"b", ... • Operations: ord, chr, =, <, ... • string • Values: "abc", "1234", ... • Operations: ^, size, =, <, ... • bool • Values: true, false • Operations: if exp then exp1 else exp2

  8. hello.sml (* print hello world *) print "hello world!\n"

  9. List • [1, 2, 3] • [] • nil • 0 :: [1, 2, 3] • fun length nil = 0  | length (_::t) = 1 + length t • [~3, ~2, ~1] @ [0, 1, 2, 3] • fun rev nil = nil | rev (h::t) = rev t @ [h]

  10. Reference • Programming in Standard ML • http://www.cs.cmu.edu/People/rwh/introsml/ • Core Language, Programming Techniques • SML/NJ FAQ • http://www.smlnj.org/doc/FAQ/index.html • SML/NJ Literature • http://www.smlnj.org/doc/literature.html • The Standard ML Basis Library • http://www.smlnj.org/basis/

  11. Quiz • square(n:int) • gcd(m:int, n:int)

  12. Quiz • square(n:int) • gcd(m:int, n:int) fun factorial(0) = 1 | factorial(n:int) = n * factorial(n-1); fun fib(n) = if n < 2 then 1 else fib(n-1)+fib(n-2);

More Related