RosettaCodeData/Task/Associative-array-Creation/OCaml/associative-array-creation-7.ocaml

8 lines
234 B
Text
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
let dict = ["foo", 5; "bar", 10; "baz", 15]
(* retrieve value *)
let bar_num = try List.assoc "bar" dict with Not_found -> 0;;
(* see if key exists *)
print_endline (if List.mem_assoc "foo" dict then "key found" else "key missing")