美文网首页
01 数据类型

01 数据类型

作者: zzzzzzzgk | 来源:发表于2016-09-09 15:52 被阅读0次
    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
    }
    

    相关文章

      网友评论

          本文标题:01 数据类型

          本文链接:https://www.haomeiwen.com/subject/ymyeettx.html