-Say you've got some moderately-complex function for searching through a list, for example:
-
- let find_nth (test : 'a -> bool) (n : int) (lst : 'a list) : (int * 'a) ->
- let rec helper (position : int) n lst =
- match lst with
- | [] -> failwith "not found"
- | x :: xs when test x -> (if n = 1
- then (position, x)
- else helper (position + 1) (n - 1) xs
- )
- | x :: xs -> helper (position + 1) n xs
- in helper 0 n lst;;