I would like to use locales as a kind of "namespace", to define functions for a general type first and then be able to concretize them for a number of different types after, like so:
locale Id =
fixes t :: 'a
begin
definition id' :: "'a ⇒ 'a" where "id' ≡ id"
end
locale IdInt = Id "(0::int)"
locale IdNat = Id "(0::nat)"
And indeed, Id.id'
is accessible at this point, but sadly IdInt.id'
and IdNat.id
are not.
What's the right way to go about this?
why not use abbreviation for that?
Max Kirchmeier said:
Id.id'
is accessible at this point, but sadly IdInt.id'
is not.
That is the behavior I expected from locales actually. If you don't introduce a new definition, why would a locale spontaneously introduce a new symbol?
Yes, that's precisely the problem, I would like the locale to introduce new symbols for things that have gotten "more concrete" :D
(I've also edited the first post to make it clear I want to be able to concretize the locale for a number of different types and not just one.)
I am not sure why you would want to do that (you also have to duplicate all theorems)
Ah, I think I've solved it:
interpretation IdInt : Id "0::int"
done
ahahah no good try
that lasts only in the current block
Mathias Fleury said:
I am not sure why you would want to do that (you also have to duplicate all theorems)
I want to do that because I have a number of operations that I would like to define for machine-words of different sizes simultaneously without re-defining everything for every word size.
Mathias Fleury said:
that lasts only in the current block
Also, it seems to work, IdInt.id'
is accessible even in other theories :P
Depends where it is defined:
locale IdInt
begin
interpretation H: Id where t = ‹0 :: int›
.
lemma H: ‹H.id' x = x›
sorry
end
context IdInt
begin
thm H
(*Id.id' ?x = ?x*)
end
Ah no, I'm not wrapping the interpretation
in a locale:
locale Id =
fixes t :: 'a
begin
definition id' :: "'a ⇒ 'a" where "id' ≡ id"
lemma id': "id' x = x" unfolding id'_def by simp
end
interpretation IdInt : Id "0::int"
done
print_statement IdInt.id'
there is global_interpretation
maximilian p.l. haslbeck said:
there is
global_interpretation
Yep, although interpretation
seems to work the same when used at theory-level:
When used on the level of a global theory, there is no end of a
current context block, hence interpretation behaves identically to
global_interpretation then.
Last updated: Dec 21 2024 at 16:20 UTC