Ocaml:错误-此表达式具有类型x,但与类型x一起使用

Ocaml:错误-此表达式具有类型x,但与类型x一起使用,ocaml,tuareg,Ocaml,Tuareg,这是我的错误: Error: This expression has type nfa but is here used with type nfa 这可能是什么原因造成的?我正在使用emacs tuareg,并逐个加载评估文件。有时会发生这种情况,有时则不会。中对此有很好的描述。发生的情况是,您使用新定义对类型定义进行了阴影处理: type nfa = int let f (x: nfa) = x type nfa = int let g (x: nfa) = x 重新启动顶层将清除旧定

这是我的错误:

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

这可能是什么原因造成的?我正在使用emacs tuareg,并逐个加载评估文件。有时会发生这种情况,有时则不会。

中对此有很好的描述。发生的情况是,您使用新定义对类型定义进行了阴影处理:

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

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

重新启动顶层将清除旧定义。

更新:

自OCaml 4.01.0(2013年9月发布)以来,一般问题是相同的,但错误消息在类型定义中添加了一个数字,以表明类型在内部是不同的

顶层中的完整示例:

类型计数器=整型计数器;;(*定义类型*)
类型计数器=整型计数器
#设x=计数器1;;(*使用新类型*)
val x:计数器=计数器1
类型计数器=整型计数器;;(*重新定义类型,使用它*)
类型计数器=整型计数器
#让递增计数器c=将c与计数器x匹配->计数器(x+1);;
增值计数器:计数器->计数器=
#递增计数器x;;(*现在混合使用旧的和新的DEF*)
错误:此表达式的类型为计数器/1029
但表达式应为counter/1032类型
# 

您可以发布生成此错误的代码吗?
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
#