这是取自http://www.angelfire.com/tx4/cus/shapes/haskell98.html的代码。如果我在模块标题中注释名称,它会在 WinGHCi 中正确编译和执行。但是如果保留名称,则它不会编译 - 它会报告名称 MakeCircle 的错误。我的问题是:如果我想明确提及我要导出 MakeCircle,需要更改哪些代码?
module Circle -- (Circle, MakeCircle, getRadius, setRadius)
where
import Shape
class Shape a => Circle a where
getRadius :: a -> Int
setRadius :: a -> Int -> a
instance Shape CircleInstance where
getX = x
getY = y
setX a newx = a {x = newx}
setY a newy = a {y = newy}
moveTo a newx newy = a {x = newx, y = newy}
rMoveTo a deltax deltay = a {x = ((getX a) + deltax), y = ((getY a) + deltay)}
draw a =
putStrLn ("Drawing a Circle at:(" ++ (show (getX a)) ++ "," ++ (show (getY a)) ++
"), radius " ++ (show (getRadius a)))
instance Circle CircleInstance where
getRadius = radius
setRadius a newradius = a {radius = newradius}
data CircleInstance = MakeCircle {x, y, radius :: Int}
deriving(Eq, Show)