moocfi / haskell-mooc

Haskell MOOC University of Helsinki
Other
313 stars 446 forks source link

Exercise 8.3 ambiguous definition #91

Closed asarkar closed 11 months ago

asarkar commented 11 months ago

Set8.hs/ Ex 3.

-- 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)
opqdonut commented 11 months ago

Thanks for the report. I've tried to clarify the exercise.