これは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)