swift中結(jié)構(gòu)體在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
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者