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

Write the times and compare functions from Exercise 11 in FICS using #lang plait. The given definitions for Z and S can be replaced by

#lang plait
(define-type Nat
  [S (pred : Nat)])
(define (plus nat1 nat2)
  (type-case Nat nat1
    [(Z) nat2]
    [(S pred) (S (plus pred nat2))]))

Your code should pass the following tests

(test (plus (Z) (S (Z))) (S (Z)))
(test (plus (S (Z)) (Z)) (S (Z)))
(test (compare (Z) (Z)) 'equal)
(test (compare (Z) (S (Z))) 'less)
(test (compare (S (Z)) (Z)) 'greater)
(test (compare (S (S (Z))) (S (Z))) 'greater)
(test (times (Z) (Z)) (Z))
(test (times (Z) (S (Z))) (Z))
(test (times (S (Z)) (Z)) (Z))
(test (times (S (S (Z))) (S (Z))) (S (S (Z))))