Advertisement
Hinski2

Untitled

May 19th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.34 KB | None | 0 0
  1. exception Found
  2. let exists f xs =
  3.     try
  4.         List.fold_left (fun acc x ->
  5.             if f x then raise Found
  6.             else false
  7.         ) false xs
  8.     with
  9.     | Found -> true
  10.  
  11.  
  12. let test1 = exists (fun x -> x == 5) [6;4;3;5];;
  13. let test2 = exists (fun x -> x == 5) [6;4;3];;
  14. let test3 = exists (fun x -> x == 5) [];;
  15. let test4 = exists (fun x -> x == 5) [5;3;2];;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement