UNB/ CS/ David Bremner/ teaching/ cs4613/ tutorials/ Lab Tutorial 2

Complete the following tutorials and hand in the PDF files via D2L

  1. Vectors 1
  2. Vectors 2
  3. Vectors 3

In the tutorial we talked about vectors that contain references to themselves. Here is the example in plait I had trouble working out at the end of the session. I had to define a recursive type to make things work, but boxes are redundant since the vector itself is mutable.

#lang plait
(define-type Thing
  [Empty]
  [Vec (v : (Vectorof Thing))])
(define vec (make-vector 5 (Empty)))
(vector-set! vec 1 (Vec vec))
vec