Skip to content

Commit 0674d64

Browse files
committed
[real-world-ocaml] update
1 parent 31455b0 commit 0674d64

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

real-world-ocaml/counter.ml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
open Base
2+
3+
type t = (string, int, String.comparator_witness) Map.t
4+
5+
let empty = Map.empty (module String)
6+
7+
let to_list t = Map.to_alist t
8+
9+
let touch t s =
10+
let count =
11+
match Map.find t s with
12+
| None -> 0
13+
| Some x -> x
14+
in
15+
Map.set t ~key:s ~data:(count + 1)

real-world-ocaml/counter.mli

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
open Base
2+
3+
(** A collection of string frequency counts *)
4+
type t
5+
6+
(** The empty set of frequency counts *)
7+
val empty : t
8+
9+
(** Bump the frequency count for the given string *)
10+
val touch : t -> string -> t
11+
12+
(** Converts the set of frequency counts to an association list. A string shows
13+
up at most once, and the counts are >= 1. *)
14+
val to_list : t -> (string * int) list

0 commit comments

Comments
 (0)