theory test
imports Main
begin
locale test2
begin
datatype foo =
foo1 "foo list" | foo2 nat
value "foo1 ([(foo2 (2:: nat))] :: foo list)"
datatype bar =
bar1 "bar list" | bar2 "bool"
value "bar1 [(bar2 (true))]"
end
end
I'm playing around with these types foo and bar (as a minimal reproducible example) and for some reason, when I try to run "value "foo1 ([(foo2 (2:: nat))] :: foo list)" in a locale, I get a type unification error:
Type unification failed: No type arity foo ::
term_of
Type error in application: incompatible operand type
As you may notice, I tried to explicitly write out the type of each subterm, to no avail
However, "value "bar1 [(bar2 (true))]" returns a value with no error in this locale.
Also more interesting: value "foo1 ([(foo2 (2:: nat))] :: foo list)" works just fine if foo and the value statement are not declared in a locale. I tried looking at StackOverflow pages and searched through threads here to little success. What exactly am I missing? Is this specifically a problem with nats and locales?
don't put datatype declaration in locales
is this a general rule-of-thumb?
the datatype package is not really localized
Sometimes you get errors, sometimes stuff stops working down the line like here
I see
is this in the datatypes manual?
also what do you mean when you say that a package "is not localized"?
what exactly does it mean to localize a package in Isabelle/HOL?
compatible with locales
oh
why is that
from my understanding, there are fundamental issues (see https://isabelle.systems/zulip-archive/stream/336180-Archive-Mirror.3A-Isabelle-Users-Mailing-List/topic/.5Bisabelle.5D.20Datatype.20definition.20in.20locale.20context.html)
so support is only going to be possible for a subset of locales
does this also mean that I can't declare a function over a type in a locale?
So it is not very motivating to fix all the tactics in the BNF package
(or recursive functions in general)
Ant S. said:
does this also mean that I can't declare a function over a type in a locale?
This works as far as I know, but you are going into issues if you want to generate code / use value
oh, I see
Mathias Fleury said:
if you want to generate code / use value
if the function is in the locale?
or if the datatype is (still) in the locale
Is that why you'd get something like "no code equations for fn, requested by dependencies"
where fn is some function
Ant S. said:
Mathias Fleury said:
if you want to generate code / use value
if the function is in the locale?
Yes. There are two issues: code equations depend on the parameters of the locale and second the function are actually abbreviations and the code generator cannot handle that
In practice, this has never really been an issue for me
I never had the case of the termination depending on the local parameters, so moving the function out of the locale was always possible
Last updated: Apr 14 2026 at 09:21 UTC