Without let
, sequence op ;
, for
and while
within the vanilla OCaml, I can write:
class c = object (self)
method f i = function
| x::_ when x <> 0 -> i
| _::xs -> self#f (i+1) xs
| [] -> failwith "Got the answer from StackOverflow"
end
;;
(new c)#f 0 [0;0;1;2;0;4;5;6];;
1
solved How to find index of First non-zero element in a list (Language – Ocaml)