7. HW B
This part uses the CodeWorld definition of a Point.
type Point = (Double, Double)
Answer the following questions. They are written with some ambiguity to avoid the question explaining exactly how to write them.
-
(
mq
) Give a number x, return the point(x, x^2)
unless this is outside of the square with $-100 \le x \le 100$ and $-100 \le y \le 100$. In that case returnNothing
. Include two more tests showing that the function works.mq :: Double -> Maybe Point mq x = Nothing check_mq = [ Nothing == mq (-200) ]
-
(
avoid
) In this question you are given a point(x0,y0)
and a list of doubles(x,y,r)
. The avoid function returns the first ordered triple that describes a circle centered at(x,y)
of radiusr
that does not contain your original point(x0,y0)
(inside or on the boundary of the circle). If there is no such triple, returnNothing
.type Circ = (Double, Double, Double) avoid :: Point -> [Circ] -> Maybe Circ