First, without knowing much about type classes, it appears that type classes are the best way to overload notation for a type, unless I can't use type classes, or haven't figured out how. I'm not using type classes.
Second, I'm pretty sure that I don't want to override notation for operators that have meaning for all types, such as \<in>
, \<times>
, *
, \<union>
, etc.
However, an operator such as +
has no meaning for my type sT
, though this ties back into my first point. I eventually would like +
to have multiple meanings for type sT => sT => sT
, which, I would think, is not going to happen.
Four versions of an example
To make my question specific and show that I'm not the only one with the problem, I take a simple example from Klein's course, the file being Demo14.thy.
After four versions of the example, I ask, "For the fourth example, can I get rid of the warnings?"
He starts with a simple example which gives no warnings or errors:
locale semi =
fixes prod :: "['a, 'a] => 'a" (infixl "\<cdot>" 70)
assumes assoc: "(x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
He uses \<cdot>
, and this represents what I've been doing so far, not using notation that has already been claimed by Isabelle/HOL.
I change his \<cdot>
to +
, and I get an error:
locale semi2 =
fixes prod :: "['a, 'a] => 'a" (infixl "+" 70)
assumes assoc: "(x + y) + z = x + (y + z)"
Having looked at the HOL sources, I've seen that +
has been defined for type ('a => 'a => 'a)
, in particular, for certain type classes.
I modify semi2
to make sure it's not specific to 'a
alone, and I then only get warnings:
locale semi3 =
fixes prod :: "('a => 'a) => ('a => 'a) => 'a" (infixl "+" 70)
assumes assoc: "(x + y) + z = x + (y + z)"
What I really care about is this fourth version, which gives a warning, even though I've inserted (x::sT)
:
locale semi4 =
fixes prod :: "sT => sT => sT" (infixl "+" 70)
assumes assoc: "((x::sT) + y) + z = x + (y + z)"
The warning is:
Ambiguous input
produces 16 parse trees (10 displayed):
[...]
Fortunately, only one parse tree is type correct,
but you may still want to disambiguate your grammar or your input.
Summary and question
For myself, I summarize it like this: The operator +
has been defined in many places, and in particular for type 'a => 'a => 'a
, which also in general defines it for sT => sT => sT
. Because of that, the prover does a lot of work, and after finally figuring out that my semi4
is the only place that +
has been defined for type sT => sT => sT
, it lets me use it.
I don't know about my summary, but can I fix semi4
so that it doesn't give me a warning?
(Note: Given the example, mathematically it would make more sense to use the symbol *
instead of +
, but *
would be notation that I wouldn't want to override.)