Skip to content

Instantly share code, notes, and snippets.

@Glorp
Created October 7, 2018 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Glorp/4c7917ad351e1340b07b1cdeb827d62c to your computer and use it in GitHub Desktop.
Save Glorp/4c7917ad351e1340b07b1cdeb827d62c to your computer and use it in GitHub Desktop.
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