考虑此示例-请注意F1
和F2
相同。
theory Scratch
imports Main
begin
locale F0 =
fixes meaning :: ‹'model ⇒ 'a set› ("⟦_⟧")
locale F1 = F0 +
fixes γ :: ‹'a set ⇒ 'model›
assumes sound: ‹L ⊆ ⟦γ L⟧›
(* Typechecks. *)
definition (in F0) "models m L ≡ L ⊆ ⟦m⟧"
locale F2 = F0 +
fixes γ :: ‹'a set ⇒ 'model›
assumes sound: ‹L ⊆ ⟦γ L⟧›
(* Does not typecheck, see below. *)
end
语言环境F2
-与类型正确的F1
相同,只不过我们向F0
添加了定义-失败,并显示错误消息:
Type unification failed
Type error in application: incompatible operand type
Operator: meaning :: 'a ⇒ 'b set
Operand: γ L :: 'model
[显然,在进行类型检查F2
时,类型检查器是否突然决定自由类型变量'a
和'model
不能是同一东西?
'a
,'b
,'c
等取代。显然,definition
命令以某种方式触发了此操作。因此,'a
中的'model
和F0
突然变成'b
和'a
。如果要覆盖此内容,则可以明确指定类型变量:
locale F2 = F0 meaning
for meaning :: "'model ⇒ 'a set" +
fixes γ :: ‹'a set ⇒ 'model›
assumes sound: ‹L ⊆ meaning (γ L)›
或
locale F2 = F0 + constrains meaning :: "'model ⇒ 'a set" fixes γ :: ‹'a set ⇒ 'model› assumes sound: ‹L ⊆ meaning (γ L)›