;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "reader.ss" "plai" "lang") (require (planet schematics/schemeunit:3) (planet schematics/schemeunit:3/text-ui)) (define-struct elephant (legs weight)) (define-struct snake (length weight)) ;; CONTRACT ;; get-weight :: (U elephant? snake?) -> number? ;; PURPOSE ;; To tell me how much an animal weighs. (define (get-weight animal) (cond [(elephant? animal) (elephant-weight animal)] [(snake? animal) (snake-weight animal)] )) (define geoffrey (make-elephant 4 1000)) (check-equal? (get-weight geoffrey) 1000)