01 數(shù)據(jù)類型

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)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容