Lab 7 Instructions #
Reminders #
-
Introduce yourself to your new lab group.
-
While other students are coming into class, follow the setup instructions below. (But please wait until you’re instructed before beginning work on the lab.)
Setup instructions #
Head to http://url.cs51.io/lab7 and follow the Lab Procedures.
Lab puzzle #
Consider the following signature for an integer queue module and its corresponding implementation, as presented in the textbook.
module type INT_QUEUE =
sig
type int_queue
val empty_queue : int_queue
val enqueue : int -> int_queue -> int_queue
val dequeue : int_queue -> int * int_queue
end ;;
module IntQueue : INT_QUEUE =
struct
type int_queue = int list
let empty_queue : int_queue = []
let enqueue (elt : int) (q : int_queue) : int_queue =
q @ [elt]
let dequeue (q : int_queue) : int * int_queue =
match q with
| [] -> raise (Invalid_argument "dequeue: empty queue")
| hd :: tl -> hd, tl
end ;;
Which of the following expressions are well formed and well typed?
A. INT_QUEUE.empty_queue ;;
B. IntQueue.enqueue 1 [] ;;
C. let open IntQueue in empty_queue ;;
D. fun (q : INT_QUEUE) -> INT_QUEUE.enqueue 1 q ;;
E. fun (q : IntQueue) -> IntQueue.enqueue 1 q ;;
F. fun (q : int_queue) -> IntQueue.enqueue 1 q ;;
G. fun (q : IntQueue.int_queue) -> IntQueue.enqueue 1 q ;;
H. None of the above.