
Exercise 11.1
1) Prove that (âˆ€cs  cs is finite) putCharList cs = map putChar cs where putCharList [] = [] putCharList (c:cs) = putChar c : putCharList cs map f [] = [] map f (x:xs) = f x : map f xs Base case: putCharList [] => [] => map putChar [] Inductive Step: assume […]

Exercise 10.4
A quick look at Graphics.SOE reveals that getWindowEvent is the right function to trap mouse down, up, and move events separately. { maybeClear is useful for avoiding flicker when not dragging objects. A real flickerfree solution should use doublebuffering of course – this code still flickers terribly while dragging. } maybeClear :: Bool > Window […]

Exercise 10.3
Prove is, to my mind, a strong word. But by substitution we can show that these functions are equivalent. First, the originals: adjust :: [(Color, Region)] > Coordinate > (Maybe (Color, Region), [(Color, Region)]) adjust regs p = case (break (\(_,r) > r `containsR` p) regs) of (top, hit:rest) > (Just hit, top++rest) (_, []) […]

Exercise 10.2
Simply run the code given in the book. The Graphics.SOE package seems to be buggy with respect to updating the window properly. I had redraw bugs using both GHCI and Hugs (using Ubuntu 7.10 on x86_84).

Exercise 10.1
This exercise is simply to execute the code given in the book. To draw the “five circles” example: draw “five circles” $ Region Blue $ Translate (2,0) $ Scale (0.5, 0.5) fiveCircles Note: Technical errors 17, 18 and 19 apply to the code (in particular shapeToGRegion) in Chapter 10.

Exercise 9.12
Instances where we can curry and convert anonymous functions to sections are easy to find, for example from Exercise 5.5: doubleEach” :: [Int] > [Int] doubleEach” = map (*2)

Exercise 9.11
map f (map g xs) = map (f.g) xs map (\x > (x+1)/2) xs = map (/2) (map (+1) xs)

Exercise 9.10
map ((/2).(+1)) xs

Exercise 9.9
fix f = f (fix f) First, f takes the result of fix f, and second, the return type of f must be the same as the return type of fix. fix :: (a > a) > a Research shows that fix is the Fixed point combinator (or Ycombinator). Apparently this allows the definition of […]

Exercise 9.8
power :: (a > a) > Int > a > a power f 0 = (\x > x) power f n = (\x > f (power f (n1) x)) Since the function is called power, there is one obvious application that springs to mind, i.e. raising to a power: raise :: Int > Int > […]