This expression has type int but an expression was expected of type Z.t

Hey guys, I can’t find the answer to this error This expression has type int but an expression was expected of type Z.t, it’s giving the error with this

match num with
			   | 0 -> Z.of_int(1)
			   | 1 -> Z.of_int(2)
			   | _ -> Z.of_int(3 * (s1 (num-1)) + (sum_s1 num))

How am I supposed to fix this error?
Any tips are always helpful!

Thanks!!

should be let open Z in of_int 3 * s1 (num-1) + sum_s1 num
* and + are overloaded by opening the module Z. Computation inside should be of type Z.t
Parentheses are not required as function application f a binds tighter than the rest

1 Like
match num with
  | 0 -> Z.of_int(1)
  | 1 -> Z.of_int(2)
  | _ -> Z.( of_int(3 * (s1 (num-1)) + (sum_s1 num)) )

Should do the trick. MyModule.( ... ) is equivalent to let open MyModule in ... but it this case I think that it is much nicer.

However, ( + ) and ( - ) are also overloaded on opening Z, so it’s not clear to me that the suggestion would typecheck. The open probably needs to be more fine-grained.

True. Both solutions ^^^ have to be refined. I missed the 1 This schroder function is recursive, so s1 and sum_s1 would be on Z too:

  let open Z in
  (of_int 3 * s1 (Int.sub num 1)) + sum_s1 num