Skip to content

Instantly share code, notes, and snippets.

@banacorn

banacorn/first.ml

Created Nov 4, 2020
Embed
What would you like to do?
let first p xs =
let length = Array.length xs in
(* mutable aray index *)
let i = ref 0 in
(* there are no loop breaks in OCaml anyway *)
let break = ref false in
while not (!break) && !i < length do
if p (xs.(!i)) then break := true else i := (!i) + 1
done;
!i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment