Recursive records in F#

前端 未结 2 804
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 08:16

A friend and I are reading up on F# and are messing around with records at the moment.

We have made the following record for representing a person:

t         


        
2条回答
  •  离开以前
    2021-01-13 09:01

    If you declare father and mother as Parent option then you can use it like:

    let f = { name = "Father"; father = None; mother = None }
    let m = { name = "Mother"; father = None; mother = None }
    let c = { name = "Child"; father = Some(f); mother = Some(m) }
    

    without using Parent option for father and mother you would have to create a "null parent" instance and use that instead of None.

提交回复
热议问题