I have a few problems creating a tree size function with type 'a option tree -> int
type 'a tree = Leaf of 'a
| Fork of 'a * 'a tree * 'a tree
How would I create a t_opt_size function with type 'a option tree -> int?
I know I would have to use Some and the None operate.
I have this so far, but it's complicated to match with the option type.
let rec t_size (tr: 'a tree): int =
match tr with
| Leaf _ -> 1
| Fork (_, t1, t2) -> t_size t1 + t_size t2 + 1
t_opt_sizedo differently thant_size? Given thatt_sizeworks on all trees, it would work on trees of options just as well without needing to change anything. - Bergi'a option treeis a subtype of'a tree, it already works. If you want to treat options different in that function, please tell us how different. - Bergi