[OCaml] High Intensity Training Online
1
(* Subjective self-reports, apart from Evidence: what the trainee said,
2
not what the body did. *)
3
4
type level = Worse_than_usual | As_usual | Better_than_usual
5
6
let pp_level ppf = function
7
| Worse_than_usual -> Format.pp_print_string ppf "worse than usual"
8
| As_usual -> Format.pp_print_string ppf "as usual"
9
| Better_than_usual -> Format.pp_print_string ppf "better than usual"
10
11
type signal = Motivation of level | Difficulty of level
12
type t = { reported_at : Recovery.timestamp; signals : signal list }
13
type error = Duplicate_signal of signal
14
15
exception Invalid of error
16
17
let same_category left right =
18
match (left, right) with
19
| Motivation _, Motivation _ | Difficulty _, Difficulty _ -> true
20
| _ -> false
21
22
let make ~reported_at signals =
23
let rec validate seen = function
24
| [] -> { reported_at; signals }
25
| signal :: rest ->
26
if List.exists (same_category signal) seen then
27
raise (Invalid (Duplicate_signal signal))
28
else validate (signal :: seen) rest
29
in
30
validate [] signals
31
32
let reported_at t = t.reported_at
33
let signals t = t.signals
34