Asterix in function signature reported by the compiler?

Hey all, I’m working through some OCaml learning resources and bumped into a compiler error I don’t know how to interpret. I’m sure my code’s doing all kindsa silly things but I’m not here to ask for implementation help or fixes. Just curious what this * means in (int * char) in the function signature reported by the compiler below.

Error: The implementation
       does not match the interface .test.eobjs/byte/nucleotide_count.cmi:
       Values do not match:
         val count_nucleotide : string -> char -> (int * char, char) result
       is not included in
         val count_nucleotide : string -> char -> (int, char) result

Thanks for any help you can offer :pray: :grinning_face_with_smiling_eyes:

* is the product type constructor. This means that (int * char) is the type representing a pair of an integer and a character. For example (1, ‘a’) is an element of type int * char.

In your specific case, the compiler has inferred that your function count_nucleotide returns an element of type (int * char, char) result, while you specified somewhere else that it should have type (int, char) result.
Most likely you wrote something along the line of
Ok (1, ‘b’) while you probably intended Ok 1.
(int, char) result is a surprising return type though - usually the second type parameter of result is set to something meaningful, while a single character makes for a poor error information


Ah! Yeah you hit the nail on the head suggesting that I’d written, Ok(1, 'b') :grinning_face_with_smiling_eyes:

Thank you!

Haha, re: the surprising return type, yeah it looks like the tests for the exercise just want the input char returned back in an error, i.e. Error 'b' if it causes a problem.

1 Like