05 - Click to edit Master subtitle style Chapter Five...

Info iconThis preview shows pages 1–11. 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: Click to edit Master subtitle style Chapter Five Modern Programming Languages, 2nd ed. A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 11 Chapter Five Modern Programming Languages, 2nd ed. ML Meta Language One of the more popular functional languages (which, admittedly, isnt saying much) Edinburgh, 1974, Robin Milners group There are a number of dialects We are using Standard ML, but we will just call it ML from now on Chapter Five Modern Programming Languages, 2nd ed. 22 Chapter Five Modern Programming Languages, 2nd ed. Chapter Five Modern Programming Languages, 2nd ed. 33 Standard ML of New Jersey- 1+2*3; val it = 7 : int- 1+2*3 = ; val it = 7 : int Type an expression after - prompt; ML replies with value and type After the expression put a ; . (The ; is not part of the expression.) If you forget, the next prompt will be = , meaning that ML expects more input. (You can then type the ; it needs.) Variable it is a special variable that is bound to the value of the expression you type Chapter Five Modern Programming Languages, 2nd ed. Outline Constants Operators Defining Variables Tuples and Lists Defining Functions ML Types and Type Annotations Chapter Five Modern Programming Languages, 2nd ed. 44 Chapter Five Modern Programming Languages, 2nd ed. Chapter Five Modern Programming Languages, 2nd ed. 55- 1234; val it = 1234 : int- 123.4; val it = 123.4 : real Integer constants: standard decimal , but use tilde for unary negation (like ~1 ) Real constants: standard decimal notation Note the type names: int , real Chapter Five Modern Programming Languages, 2nd ed. Chapter Five Modern Programming Languages, 2nd ed. 66- true; val it = true : bool- false; val it = false : bool Boolean constants true and false ML is case-sensitive: use true , not True or TRUE Note type name: bool Chapter Five Modern Programming Languages, 2nd ed. Chapter Five Modern Programming Languages, 2nd ed. 77- "fred"; val it = "fred" : string- "H"; val it = "H" : string- #"H"; val it = #"H" : char String constants: text inside double quotes Can use C-style escapes: \n , \t , \\ , \" , etc. Character constants: put # before a 1-character string Note type names: string and char Chapter Five Modern Programming Languages, 2nd ed. Outline Constants Operators Defining Variables Tuples and Lists Defining Functions ML Types and Type Annotations Chapter Five Modern Programming Languages, 2nd ed. 88 Chapter Five Modern Programming Languages, 2nd ed. Chapter Five Modern Programming Languages, 2nd ed. 99- ~ 1 + 2 - 3 * 4 div 5 mod 6; val it = ~1 : int- ~ 1.0 + 2.0 - 3.0 * 4.0 / 5.0; val it = ~1.4 : real Standard operators for integers, using ~ for unary negation and - for binary subtraction Same operators for reals, but use / for division Left associative, precedence is { + ,- } < { * , / , div , mod } < { ~ }. Chapter Five Modern Programming Languages, 2nd ed....
View Full Document

Page1 / 56

05 - Click to edit Master subtitle style Chapter Five...

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

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