Exercise 72 From How To Design Programs

:: Learning, SoftwareEngineering, HtDP

By: Onorio Catenacci

My response for Exercises 72 and 73 (Chapter 5.6) of How to Design Programs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#lang typed/racket

; Exercise 72
(struct phone-number ([area : String] [switch : String] [num : String]))
(struct entry ([name : String] [phone : phone-number] [email : String]))

; Exercise 73
(struct posn ([x : Number] [y : Number]))

(: posn-up-x (-> posn Number posn))
(define (posn-up-x p n)
  (posn (+ (posn-x p) n) (posn-y p)))

I’m using Typed Racket here rather than BSL because unless I need to do some graphic work I don’t see any reason to solve the problems in BSL since that’s ultimately a dead end.