Lab 2: The design recipe
Important Note: Whenever you write a function in this class, you need to follow the design recipe. In particular, every type mentioned in a signature must be introduced by a data definition, except for these well-known types: Number, Image, String, Color.
1 Designing functions
To practice the design recipe, let’s re-do some exercises from Problem set 2: Robert Indiana. Refer to your work on it, and feel free to ask questions about it as always.
Exercise 1. Design a function cube that takes a number as input and returns its cube. Write at least two examples using check-expect.
Exercise 2. Design a function diamond that takes a string and returns an image of it inside a circle inside a diamond. Write at least two examples using check-expect.
Exercise 3. Design a function arrow that takes two colors and returns an image of an arrow of the first given color inside a circle of the second given color. Write at least two examples using check-expect.
2 Composing functions
; diamond : String -> Image ; beside : Image Image -> Image
; arrow : Color Color -> Image ; rotate : Number Image -> Image ; beside : Image Image -> Image ; above : Image Image -> Image
; cube : Number -> Number ; diamond : String -> Image ; number->string : Number -> String
3 Extra fun
Exercise 7. Design a function vertical-triband that takes three colors as inputs and produces a vertical triband flag image that is 150 wide and 100 tall, such as the flag of France. Write at least two examples using check-expect.
Exercise 8. Some triband flags have horizontal rather than vertical bands. For example, the flag of the Netherlands has three horizontal bands, whose colors are dark red, white, and dark blue. Use vertical-triband to design a function horizontal-triband that takes three colors as inputs and produces a horizontal triband flag image. Write at least two examples using check-expect.