F# 使用区分大小写的联合作为记录
示例
有时创建仅具有一种情况的联合类型以实现类似记录的类型很有用:
type Point = Point of float * float let point1 = Point(0.0, 3.0) let point2 = Point(-2.5, -4.0)
这些变得非常有用,因为它们可以通过模式匹配以与tuple参数相同的方式分解:
let (Point(x1, y1)) = point1
//值x1:浮点数=0.0
//valy1:浮点=3.0
let distance (Point(x1,y1)) (Point(x2,y2)) =
pown (x2-x1) 2 + pown (y2-y1) 2 |> sqrt
// val distance : Point -> Point -> float
distance point1 point2
//valit:float=7.433034374
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短