Ocaml: Error - this expression is of type x, but is used with type x

That's my fault:

Error: This expression has type nfa but is here used with type nfa 

What could be the reason for this? I use emacs tuareg and upload assessment files one by one. Sometimes this happens, and in other cases it is not.

+6
ocaml tuareg
source share
2 answers

A good description of this in the ocaml tutorial . It so happened that you obscured the type definition with the new definition:

 type nfa = int let f (x: nfa) = x type nfa = int let g (x: nfa) = x 

Restarting the top level will clear the old definitions.

+10
source share

Update:

Since OCaml 4.01.0 (released September 2013), the general problem is the same, but the error message adds a number to the type definition to make it obvious that the types are internally different.

A complete example from old OCaml FAQs in a top-level file:

 type counter = Counter of int;; (* define a type *) type counter = Counter of int # let x = Counter 1;; (* use the new type *) val x : counter = Counter 1 type counter = Counter of int;; (* redefine the type, use it *) type counter = Counter of int # let incr_counter c = match c with Counter x -> Counter (x + 1);; val incr_counter : counter -> counter = <fun> # incr_counter x;; (* now mix old and new defs *) Error: This expression has type counter/1029 but an expression was expected of type counter/1032 # 
0
source share

All Articles