问题
Given this code
locale A =
fixes foo :: "'a"
locale B = A +
fixes bar :: "'a × 'a"
locale C' = A +
fixes baz :: "'a"
begin
sublocale B foo "(foo, baz)".
end
I get
Type unification failed
Failed to meet type constraint:
Term: (foo, baz) :: 'b × 'a
Type: 'b × 'b
so it seems that Isabelle does not understand that baz
and foo
should be of the same type. Is there a way to fix this?
回答1:
The problem is with your declaration of locales B
and C
. The declaration for B
is equivalent to the following
locale B = A foo for foo +
fixes bar :: "'a * 'a"
Locales imports only remember the names of the parameters, but not the names of type variables. Thus, as you have not specified the type for foo
, the most general type for B
's parameter is the following:
foo :: 'b
bar :: 'a * 'a
You can see this using the command print_locale B
. The same happens in the declaration of locale C
.
If you want to have the same type for foo
and bar
, you have to make the connection explicit in the locale declarations. There are two ways to do this.
locale B = A foo
for foo :: 'a
+
fixes bar :: "'a * 'a"
and
locale B = A +
constrains foo :: 'a
fixes bar :: "'a * 'a"
来源:https://stackoverflow.com/questions/26253538/fixing-type-variables-in-locale-extensions