i'm doing basic work in haskell , don't understand why isn't compiling. here's error:
shapes.hs:35:11: no instance (floating int) arising use of `sqrt' in expression: sqrt (hd * hd + vd * vd) in equation `d': d = sqrt (hd * hd + vd * vd) in expression: let hd = xc - x vd = yc - y d = sqrt (hd * hd + vd * vd) in if d <= r true else false related code:
type point = (int,int) data figure = rect point point | circ point int inside :: point -> figure -> bool inside (x,y) (rect (left,bot) (right,top)) = if x <= left && x >= right && y <= bot && y >= top true else false inside (x,y) (circ (xc,yc) r) = let hd = xc - x vd = yc - y d = sqrt (hd*hd + vd*vd) in -- line 35 here if d <= r true else false the sqrt function's type floating => -> -> a->. doesn't num auto convert floating, or not problem?
change circ handling code , typecheck:
inside (x,y) (circ (xc,yc) r) = let hd = fromintegral $ xc - x vd = fromintegral $ yc - y d = sqrt (hd*hd + vd*vd) in if d <= (fromintegral r) true else false the type of sqrt sqrt :: floating => -> a , have proper type conversion using fromintegral make typecheck.
Comments
Post a Comment