
















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The key points are: First Look at Ml, Meta Language, Popular Functional Languages, Robin Milner’s Group, Number of Dialects, Special Variable, Defining Variables, Tuples and Lists, Defining Functions, Type Annotations
Typology: Slides
1 / 56
This page cannot be seen from the preview
Don't miss anything!

















































Chapter Five Modern Programming Languages, 2nd ed. (^) Docsity.com 1
Chapter Five Modern Programming Languages, 2nd ed. (^) Docsity.com 2
Chapter Five Modern Programming Languages, 2nd ed. (^) Docsity.com 4
Chapter Five Modern Programming Languages, 2nd ed. 5
val it = 1234 : int
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. 7
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. (^) Docsity.com 8
Chapter Five Modern Programming Languages, 2nd ed. 10
String concatenation: ^ operator Ordering comparisons: < , > , <= , >= , apply to string , char , int and real
Order on strings and characters is lexicographic
Chapter Five Modern Programming Languages, 2nd ed. 11
val it = false : bool
Equality comparisons: = and <>
Most types are equality testable: these are equality types Type real is not an equality type
Chapter Five Modern Programming Languages, 2nd ed. 13
Note: andalso and orelse are short-circuiting operators: if the first operand of orelse is true, the second is not evaluated; likewise if the first operand of andalso is false
Technically, they are not ML operators, but keywords All true ML operators evaluate all operands
Chapter Five Modern Programming Languages, 2nd ed. 14
Conditional expression (not statement) using if … then … else … Similar to C's ternary operator: (1<2)? 'x' : 'y' Value of the expression is the value of the then part, if the test part is true, or the value of the else part otherwise There is no if … then construct
Chapter Five Modern Programming Languages, 2nd ed. 16
val it = 2 : int
The ***** operator, and others like + and < , are overloaded to have one meaning on pairs of integers, and another on pairs of reals ML does not perform implicit type conversion
Chapter Five Modern Programming Languages, 2nd ed. 17
You apply a function to an argument in ML just by putting the function next to the argument. Parentheses around the argument are rarely necessary, and the usual ML style is to omit them
Chapter Five Modern Programming Languages, 2nd ed. 19
Function application has higher precedence than any operator Be careful!
Chapter Five Modern Programming Languages, 2nd ed. 20
What if anything is wrong with each of these expressions? trunc 5 ord "a" if 0 then 1 else 2 if true then 1 else 2. chr(trunc(97.0)) chr(trunc 97.0) chr trunc 97.