I was trying this construct:
type Tree<'a> =
| Leaf
| Node of { value:'a ; left:Tree<'a> ; right:Tree<'a> }
But f# does not seem to support this (strange). But then how to do this with a separate record type, one then gets stuck in a circular dependency.
Use the keyword and to deal with circular dependencies:
type Rec<'a> = { value:'a ; left:Tree<'a> ; right:Tree<'a> }
and Tree<'a> =
| Leaf
| Node of Rec<'a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With