swift中结构体在haskell中的描述
struct Resolution {
var width = 0
var height = 0
}
data Resolution = Resolution{
width :: Integer ,
hight :: Integer
}
r1 = Resolution 640 480
test00 = width r1 == 640
test01 = hight r1 == 480
data Resolution1 = Resolution1 Integer Integer
width1 (Resolution1 w _ ) = w
hight1 (Resolution1 _ h ) = h
r2 = Resolution1 640 480
test02 = width1 r2 == 640
test03 = hight1 r2 == 480
枚举类型在haskell中的描述
enum CompassPoint{
case North
case South
case East
case West
}
data CompassPoint = North|South|East|West
枚举携带类型在haskell中描述
enum Shape{
case Circle(Float,Float,Float)
case Rectangle(Float, Float, Float, Float)
}
data Shape = Circle Float Float Float | Rectangle Float Float Float Float
递归类型
data Tree a = Node a (Tree a) (Tree a)
| Empty
deriving (Show)
indirect enum Tree<T> {
case Node(T,Tree,Tree)
case Empty
}
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。