[OCaml] - How to reimplement assoc with a more truthful | SheCodes

[OCaml] - How to reimplement assoc with a more truthful type in OCaml

Learn how to use options to re-implement the API 'assoc' with a more meaningful type in OCaml

πŸ‘©β€πŸ’» Technical question

in ocaml Use options to re-implement `assoc` with a more truthful type: let rec assoc : (key: 'k) (l : ('k * 'v) list) : 'v = begin match l with | [] -> failwith "Not_found" | (k2, v) :: tl -> if key = k2 then v else assoc key tl end