-- Ex 3: implement a rectangle. The value of `rectangle x0 y0 w h`
-- should be a rectangle with the upper left corner at (x0, y0), a
-- width of w, and a height of h.
--
-- Example:
-- renderList (fill white (rectangle 1 2 4 3)) (0,5) (0,5)
-- ==> [["000000","000000","000000","000000","000000","000000"],
-- ["000000","000000","000000","000000","000000","000000"],
-- ["000000","ffffff","ffffff","ffffff","ffffff","000000"],
-- ["000000","ffffff","ffffff","ffffff","ffffff","000000"],
-- ["000000","ffffff","ffffff","ffffff","ffffff","000000"],
-- ["000000","000000","000000","000000","000000","000000"]]
The solution, shown below, accepts coordinates on the x0 and y0 lines (>=), i.e. the top and the left sides of the rectangle, but doesn't accept coordinates on the far sides of the rectangle (<).
There's no way for a student to know this other than by frustrating trial and error. Please update the problem description to state this requirement clearly.
rectangle :: Int -> Int -> Int -> Int -> Shape
rectangle x0 y0 w h = Shape f
where
f (Coord x y) = x >= x0 && x < (x0 + w) && y >= y0 && y < (y0 + h)
Set8.hs/ Ex 3.
The solution, shown below, accepts coordinates on the
x0
andy0
lines (>=
), i.e. the top and the left sides of the rectangle, but doesn't accept coordinates on the far sides of the rectangle (<
).There's no way for a student to know this other than by frustrating trial and error. Please update the problem description to state this requirement clearly.