在Haskell中,我可以做类似的事情(示例改编自Learn You A Haskell)
module Shapes (
Shape,
newCircle,
newRectangle,
... -- other functions for manipulating the shapes
)
data Shape = Circle Int Int Float -- x, y, radius
| Rectangle Int Int Int Int -- x1, y1, x2, y2
newCircle :: Float -> Shape
newCircle r = Circle 0 0 r
newRectangle :: Int -> Int -> Shape
newRectangle w h = Rectangle 0 0 w h
... -- other functions for manipulating the shapes
这将允许我只公开Shape
类型以及newCircle
和newRectangle
函数.
rust 迹是否也有类似的作用?