Can't make exercise from Jason Hickey's "Introduction to Objective Caml" book
I'm trying to solve this exercise:
Suppose you have a function on integers f : int -> int that is mono-
tonically increasing over some range of arguments from 0 up to n. That is,
f i < f (i + 1) for any 0 ¡Ü i < n. In addition f 0 < 0 and f n > 0. Write
a function search f n that finds the smallest argument i where f i ¡Ý 0.
Now i wrote this
let search f n =
let min = f 0 in
let rec searchin i =
if i >= n then min
else
if f min > f i then min = i
searchin i+1;;
But it crashes with error:
Error: Parse error: "in" expected after [binding] (in [expr])
What wrong? And my implementation is correct?
No comments:
Post a Comment