Reputation: 6279
I trying to compile a code and it gives me a non-sense error, I'm very new to oCaml so I'm missing something for sure
Here is the code
let foo () =
if '\n' = '\n' then begin
print_endline "foo";
end
Here is the error when I run dune build
File "gkoeditor.ml", line 46, characters 7-11:
46 | if '\n' = '\n' then begin
^^^^
Error: This expression has type char but an expression was expected of type
int
The whole source code can be found here https://github.com/dhilst/gkoeditor
I'm using Curses and Core libraries, for sure something is messing up with my environment,
Regards
Upvotes: 1
Views: 110
Reputation: 66818
I believe that Core
overrides the definition of =
so that it is of type int -> int -> bool
. The justification is that the polymorphic comparison sometimes causes problems. (It can cause an exception if the types contain functions, and can diverge in the presence of cyclic structures.)
Polymorphic =
has never caused me any problems, and I find this redefinition to be a bit troubling for exactly the reason that it generates errors that seem to make no sense. However I can see the advantages.
At any rate, you can fix this by asking specifically for the polymorphic version of =
in the Poly
module.
Upvotes: 2