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