Is there a way to refer to the type that implements the type class? For example given a class like this:
class foo = assumes "P UNIV"
how can I ensure that an instance declaration uses the correct UNIV
?
instantiation nat :: foo begin
instance apply standard
(* How do I make sure that the goal is "P (UNIV :: nat set)" here? *)
IsaFoR uses a type_fixer
parameter for such case:
class foo = fixes type_fixer :: "'a" assumes "P (UNIV :: 'a set)"
instantiation nat :: foo
begin
definition type_fixer_nat :: ‹nat itself› where
‹type_fixer_nat ≡ TYPE(nat)›
instance apply standard
sorry
thought about something like that, but nothing would prevent me to use TYPE(unit)
there, wouldn't it?
No.
I guess it just has to be documented that it needs to be the same type as the type that the class is defined for. Weird that there is no syntax for this, in Haskell it would be easy:
class Foo a where x :: P (UNIV a)
in isabelle this could look similar:
class 'a foo = (* ... *)
wait
class foo =
assumes finite_UNIV: "P (UNIV :: 'a set)"
begin
end
instantiation nat :: foo
begin
instance
supply [[show_sorts, show_types]]
apply standard
does what you want right?
I checked how finite
does it
ehh, what should I see? It does not show me the type of UNIV
no but of P
and P has the right type
is there a way to get isabelle to show the types of constants e.g. on ctrl+hover?
I don't know any
apply (tactic ‹SUBGOAL (fn (t, _) =>
let val _ = @{print} t
in all_tac end) 1
›)
works and it confirms that it has the correct type. Interesting
Jan van Brügge has marked this topic as resolved.
Just to confirm, in the context of a type class, the type that you're talking about is always 'a
.
Last updated: Dec 21 2024 at 16:20 UTC