09 SML0 - SML • Download from http/www.smlnj.org • From...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SML • Download from http://www.smlnj.org/ • From wikipedia entry – 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 … It is unique among widely used languages in that it has a formal specification, given as typing rules and an operational semantics in The Definition of Standard ML (1990, revised and simplified as The Definition of Standard ML (Revised) in 1997). • Read about the ML type system in Supplement to Chapter 7. • Links to several books and tutorials at the smlnj web site. 1 • ML session seems like an interpreter session (but really compiled) • Terminate session with <eof> character (cntr d on unix, cntr z on windows) • Can create definitions in a file with any text editor and read into your session with function use , which take a string containing the file name as an argument use “mlprogram.sml”; • For debugging, it is helpful if your editor displays line numbers. 2 Elements of ML (incomplete) primitive types: int, real, char, string, bool 3 tuples: (3,4): int * int, (“hello”, 4, 5): string * int * int (“pi”, 3.14159): string * real 4 lists [3,4]: int list [“adios”, “goodbye”, “auf wiedersehen”]: string list build list using , the empty list, nil :: , the cons operator, which makes a new list by putting element in front of an existing list 4:: = [4] 3::[4] = [3,4] 5 functions • ML is functional programming language: • programs are functions (functions have types) • running a program is evaluating an expression • variables are like variables as in mathematics – no assignment statement in a pure functional language (although ML is not pure) – no side effects in expressions 6 val z = 3; val z = 3: int • val is the keyword to declare a new variable and bind it to a value • ; tells interpreter to elaborate, compile, evaluate and print results (allows typing on multiple lines) • blue lines are entered by the programmer • red lines are the response by SML 7 val z = 3; val z = 3: int z; val it = 3:int (result of evaluating z wasn’t bound to anything, ml binds it to “it”) it; val it = 3:int val y = z + 1; val y = 4: int y; val it = 4: int 8 Redefining names (some output omitted) val z = 3; val y = z+1: int val z = 1; y; 4 IMPORTANT: previous bindings don’t...
View Full Document

This note was uploaded on 12/09/2009 for the course COP 5555 taught by Professor Staff during the Fall '08 term at University of Florida.

Page1 / 158

09 SML0 - SML • Download from http/www.smlnj.org • From...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online