Practice question from FSharp Programming Advanced
Complete the discriminated union pattern matching:
type Tree<'a> =
| Leaf of 'a
| Node of Tree<'a> * Tree<'a>
let rec depth tree =
match tree with
| Leaf(_) -> ____
| Node(left, right) -> 1 + ____ (max depth left depth right)Answer
["0","max"]
Explanation
Leaf depth is 0, and Node depth is calculated by taking the max of left and right subtree depths and adding 1.