

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


This assignment covers material through Chapter 4 of Haskell: The Craft of Func- tional Programming.
This homework is officially due in the bin in CST 3-212 by noon on Thursday, February 5. However, it comes with an automatic extension: anything submit- ted by noon on Friday, February 6 will be accepted as being on time.
You may work singly or in pairs on this assignment.
You should turn in a hard copy of your source code and a transcript demon- strating convincingly that your code is correct. You should also submit your code (but not the transcript) electronically , as described on the course web site.
You should follow the design recipe and documentation requirements. How- ever, you do not need to include examples or test cases in your code (they’d be way too big). Instead, simply write “See the Homework 3 write-up for exam- ples” in the EXAMPLES part of your comments.
You may use any code from lecture that you wish: in fact, we encourage you to do so. However, you should include a note in your comments indicating that you are doing so and specifying which functions you are reusing.
You will again need the file Pictures.lhs to use the Pictures module. Do not add your code to this file. Instead, you should include an import Pictures directive at the top of your file.
altThree :: Int -> Picture -> Picture -> Picture -> Picture
such that altThree n pic1 pic2 pic3 returns a row of n pictures, as fol- lows: every odd-indexed picture is pic1, and the even-indexed pictures cycle between pic2 and pic3.
indexRow :: Int -> Int -> Picture -> Picture -> Picture
such that indexRow c n pic1 pic2 returns a row of n pictures: pic1 is at index c, and pic2 occurs everywhere else. Your code should raise an error if either c or n is less than 1. Note: You may assume that c is never greater than n.
stripes :: Int -> Int -> Picture -> Picture -> Picture
such that stripes m n pic1 pic2 returns an m × n grid of pictures, with pic1 appearing on the 1st^ and mth^ rows, as well in all odd-numbered columns; pic2 should appear everywhere else. Your code should raise an error if either m or n is less than 1, or if n is even.
leftTri :: Int -> Picture -> Picture -> Picture
such that leftTri n pic1 pic2 returns an n × n grid, as follows:
Your code should raise an error if n is less than 1.
Final comments: For the last question especially, I strongly encourage you to think out your solutions with paper first, before sitting down to write code. Also, if any of your functions is longer than about five lines (not counting helper func- tions), then you’re probably making things more complicated than they need to be.
The following examples make use of these definitions of white, black, blob, and exx used in lecture.
Main> printPicture (altThree 10 white blob exx) .......#.......#...#.......#.......#...#.......#.. ......###.......#.#.......###.......#.#.......###. ......###........#........###........#........###. ......###.......#.#.......###.......#.#.......###. .......#.......#...#.......#.......#...#.......#..
Main> printPicture (altThree 7 white blob exx) .......#.......#...#.......#....... ......###.......#.#.......###...... ......###........#........###...... ......###.......#.#.......###...... .......#.......#...#.......#.......
Main> printPicture (indexRow 3 7 white blob) ..#....#.........#....#....#....#.. .###..###.......###..###..###..###. .###..###.......###..###..###..###. .###..###.......###..###..###..###. ..#....#.........#....#....#....#..
Main> printPicture (indexRow 7 7 white blob) ..#....#....#....#....#....#....... .###..###..###..###..###..###...... .###..###..###..###..###..###...... .###..###..###..###..###..###...... ..#....#....#....#....#....#.......
Main> printPicture (indexRow 1 7 white blob) .......#....#....#....#....#....#.. ......###..###..###..###..###..###. ......###..###..###..###..###..###. ......###..###..###..###..###..###. .......#....#....#....#....#....#..
Main> printPicture (stripes 6 7 blob white) ..#....#....#....#....#....#....#.. .###..###..###..###..###..###..###. .###..###..###..###..###..###..###. .###..###..###..###..###..###..###. ..#....#....#....#....#....#....#.. ..#.........#.........#.........#.. .###.......###.......###.......###. .###.......###.......###.......###. .###.......###.......###.......###. ..#.........#.........#.........#.. ..#.........#.........#.........#.. .###.......###.......###.......###. .###.......###.......###.......###. .###.......###.......###.......###. ..#.........#.........#.........#.. ..#.........#.........#.........#.. .###.......###.......###.......###. .###.......###.......###.......###. .###.......###.......###.......###. ..#.........#.........#.........#.. ..#.........#.........#.........#.. .###.......###.......###.......###. .###.......###.......###.......###. .###.......###.......###.......###. ..#.........#.........#.........#.. ..#....#....#....#....#....#....#.. .###..###..###..###..###..###..###. .###..###..###..###..###..###..###. .###..###..###..###..###..###..###. ..#....#....#....#....#....#....#..