Advertisement
Hinski2

Untitled

May 19th, 2024
915
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.36 KB | None | 0 0
  1. let find (type t) p (xs : t list) =
  2.     let exception Found of t in
  3.     try
  4.         List.fold_left (fun _ x ->
  5.             if p x then raise (Found x)
  6.             else ()
  7.         ) () xs;
  8.         raise Not_found
  9.     with
  10.     | Found x -> x
  11.  
  12. let pred = fun x -> x >= 5;;
  13. let test1 = find pred [6;4;3;5];;
  14. let test2 = find pred [4; 3; 1];;
  15. let test3 = find pred [];;
  16. let test4 = find pred [4;3;6;7];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement