0
votes

Starting to learn OCAML.
Let's assume we have one check function:

let check x y = if (y mod x) = 0 then true else false;;

Then for any given couple a b, I would like to iterate to find the couple i j that would satisfy: 1 < i <= a AND 1 < j <= b and check i j = true. I am iterating i downto 1 and j (up)to b.

let g (x, y) = 
      let rec gf i j = 
    if check i j then (i, j) else gs i j 
      and gs i j = 
    if check i j then (i, j) else 
          if j <= y then gs i (j + 1) else
        if i > 1 then gf (i - 1) j else (-1, -1)
         in (gf x 1 &&  gs x 1);;

But I get error:

Error: This expression has type int * int
       but an expression was expected of type bool

I do not see where I have a bool returned from that g (x, y) function. There maybe a simpler way to write (hey, I am new), but i'd like to understand the logic here.

1

1 Answers

2
votes

The problem is in this expression:

gf x 1 && gs x 1

The && operator takes a boolean value at the left and right, and returns a boolean. But your gf and gs functions each return a pair of ints. The compiler is telling you that you have a pair of ints (int * int) but you need a boolean (as an operand of the && operator).