Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
let hash = Hashtbl.create 0;;
|
||||
List.iter (fun (key, value) -> Hashtbl.add hash key value)
|
||||
["foo", 5; "bar", 10; "baz", 15];;
|
||||
|
|
@ -0,0 +1 @@
|
|||
let bar = Hashtbl.find hash "bar";; (* bar = 10 *)
|
||||
|
|
@ -0,0 +1 @@
|
|||
let quux = try Hashtbl.find hash "quux" with Not_found -> some_value;;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
module String = struct
|
||||
type t = string
|
||||
let compare = Pervasives.compare
|
||||
end
|
||||
module StringMap = Map.Make(String);;
|
||||
|
||||
let map =
|
||||
List.fold_left
|
||||
(fun map (key, value) -> StringMap.add key value map)
|
||||
StringMap.empty
|
||||
["foo", 5; "bar", 10; "baz", 15]
|
||||
;;
|
||||
|
|
@ -0,0 +1 @@
|
|||
let bar = StringMap.find "bar" map;; (* bar = 10 *)
|
||||
|
|
@ -0,0 +1 @@
|
|||
let quux = try StringMap.find "quux" map with Not_found -> some_value;;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue