#lang plait (print-only-errors #t) (define-type Robot-ins (forward [feet : Number]) (left) (right)) (define (amount-forward [ins : Robot-ins]) (type-case Robot-ins ins [(forward f) f] [(left) 0] [(right) 0])) (test (amount-forward (forward 10)) 10) (test (amount-forward (left)) 0) (test (amount-forward (right)) 0) ;; ---------------------------------------- #; (define-type (Listof Robot-ins) empty (cons [item : Robot-ins] [rst : (Listof Robot-ins)])) (define (total-distance [inss : (Listof Robot-ins)]) (type-case (Listof Robot-ins) inss [empty 0] [(cons item r) (+ (amount-forward item) (total-distance r))])) (test (total-distance empty) 0) (test (total-distance (cons (forward 4) (cons (left) empty))) 4)