Instantly share code, notes, and snippets.

Embed
What would you like to do?
datatype fruit =
Peach
| Apple
| Pear
| Lemon
| Fig
datatype tree =
Bud
| Flat of fruit * tree
| Split of tree * tree
(* height : tree -> int *)
fun height Bud = 0
| height (Flat(_, t)) = 1 + height (t)
| height (Split(s, t)) = 1 + Int.max (height(s), height(t))
val smol_tree = Split (Bud, Flat (Peach, Bud))
val larger_tree = Split (Flat (Apple, Flat (Lemon, Bud)), Flat (Peach, Bud))
val smol_height = height smol_tree
val larger_height = height larger_tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment