
CS 3721: Programming Languages Lab
Lab #07: Programming in ML
Due date: March 11, 3:30pm. At the beginning of the next recitation.
Goals of this lab:
•Be able to interact with ML and interpret ML’s response ;Be able to write simple
expressions of numbers, booleans and tuples ;Be able to list several of ML’s basic
primitive types and write expressions belonging to those types ;Be able to read/write
expressions constructing tuples ;Be able to write val declarations and expressions using
pattern matching on tuples ;Be able to declare functions using fun
1. Primitive types. For ML expressions, user interaction with the ML compiler has the
form:
-<expression>;
val it = <value> : <type>
First line is the user input, and the second one is output from the ML compiler and run-
time system. it is a special identifier bound to the value of the last expression entered.
Therefore, “it = <value>:<type>” means that the value of the expression is < value >
and its type is < type >. The keyword val stands for value. Now, you’ve learned how
to interpret the output from the ML compiler. Followings are some expressions. Please,
write down their values and types (fill in the blanks).
- 3487 + (45 - 691); ==> val _____ = _____ : _____
- "cs utsa"; ==> val _____ = _____ : _____
- 55 <> 4; ==> val _____ = _____ : _____
- (14.3 - 3.7) + 5.8; ==> val _____ = _____ : _____
- it + 3.6; ==> val _____ = _____ : _____
2. Operations provided to support int values. “+, -, *, div” are binary infix operators on
integers. Find out the result of 2+3∗6−1
3. Write down your ML expression, and the
output. (In ML, 1-tuples are used for grouping subexpressions like parentheses used in
C/JAVA.)
3. Operations provided to support real values. “+, -, *, /” are binary infix operators on
reals. Find out the result of 2.4 + 3.2∗6.21 −1.1
3.4. Write down your ML expression, and the
output.
4. Operations provided to support bool values. “andalso, orelse, not” are operators on bools.
Find out the result of the expression, “(true ∧2 = 2) ∨5<> 5∨ ¬(3 = 4)”.
Write down your ML expression, and the output. (“<>” is the not equal operator.)
1