zoukankan      html  css  js  c++  java
  • F#基本类型——Structure

    Structure是F#的基本类型之一,和C#中的struct对应,其语法结构如下:

        [ attributes ]
        type [accessibility-modifier] type-name =
            struct
                type-definition-elements
            end

    一个简单的struct定义为

        type Point3D =
            struct
                val x: float
                val y: float
                val z: float
            end

    但这种方式并不是lightweight,实际也很少这么使用,通过lightweight语法简化后的形式为:

        [ attributes ]
        [<StructAttribute>]
        type [accessibility-modifier] type-name =
            type-definition-elements

    因此,我们用这种方式也能到达上述同样的效果:

        [<StructAttribute>]
        type Point3D2 =
            val x: float
            val y: float
            val z: float

    Structure不能使用let或do绑定,只能通过val声明成员变量。因此,其各成员是有默认值的。另外,它也能说明成员函数,由于这部分内容和class比较类似,这里就不做详细介绍了。

  • 相关阅读:
    POJ Countries in War 3114
    POJ 2553 The Bottom of a Graph
    POJ 2762 Going from u to v or from v to u?(强联通 + TopSort)
    POJ 3180 The Cow Prom(强联通)
    HDU 4738 Caocao's Bridges
    喵哈哈村的几何大师╰☆莣メ誋こ月
    Vladik and Entertaining Flags
    XOR Queries
    Palindrome
    F
  • 原文地址:https://www.cnblogs.com/TianFang/p/1655309.html
Copyright © 2011-2022 走看看