Files
comp3958/lectures/09/list_monad.ml
T
2026-03-12 11:55:15 -07:00

19 lines
380 B
OCaml

let return x = [x]
let ( >>= ) l f = List.concat_map f l
let gaurd cond l =
if cond then l else []
let multiply_to n =
List.init n ((+) 1) >>= fun x ->
List.init n ((+) 1) >>= fun y ->
gaurd (x * y = n) [(x, y)]
let ( let* ) = ( >>= )
let multiply_to' n =
let* x = List.init n ((+) 1) in
let* y = List.init n ((+) 1) in
if x * y = n then [(x, y)] else []