Created
October 7, 2018 11:55
-
-
Save Glorp/4c7917ad351e1340b07b1cdeb827d62c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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