Skip to content

Instantly share code, notes, and snippets.

@loganknecht
Last active April 13, 2018 22:17
Show Gist options
  • Save loganknecht/74ddb2d5bfafdf5b31834aa54908c82b to your computer and use it in GitHub Desktop.
Save loganknecht/74ddb2d5bfafdf5b31834aa54908c82b to your computer and use it in GitHub Desktop.
OCaml Lab 1 Head Scratching
type ('key, 'value) avlnode =
| Leaf
| Node of int *
'key *
'value *
('key, 'value) avlnode *
('key, 'value) avlnode
let rec get (node_to_search : ('key, 'value) avlnode)
(key_to_search_for : 'key)
: 'value option =
match node_to_search with
| Leaf -> None
| Node(_, node_key, node_value, node_left_child, node_right_child) ->
if node_key = key_to_search_for
then Some(node_value)
else if key_to_search_for < node_key
then (get node_left_child key_to_search_for)
else (get node_right_child key_to_search_for)
(* None of this works for me *)
(*
let output = (get a_tree "a")
let print_get_output (output_from_get_function : 'output) =
match output_from_get_function with
| Leaf -> Printf.printf "Leaf"
| _ -> Printf.printf "Default"
;;
(print_get_output output)
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment