01 数据类型

2016-09-09  本文已影响0人  zzzzzzzgk
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
}
上一篇下一篇

猜你喜欢

热点阅读