Stream: Beginner Questions

Topic: Use type in class declaration


view this post on Zulip Jan van Brügge (Jun 30 2022 at 12:56):

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? *)

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:05):

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

view this post on Zulip Jan van Brügge (Jun 30 2022 at 13:06):

thought about something like that, but nothing would prevent me to use TYPE(unit) there, wouldn't it?

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:10):

No.

view this post on Zulip Jan van Brügge (Jun 30 2022 at 13:15):

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)

view this post on Zulip Jan van Brügge (Jun 30 2022 at 13:15):

in isabelle this could look similar:

class 'a foo = (* ... *)

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:22):

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?

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:23):

I checked how finite does it

view this post on Zulip Jan van Brügge (Jun 30 2022 at 13:38):

ehh, what should I see? It does not show me the type of UNIV

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:39):

no but of P

view this post on Zulip Mathias Fleury (Jun 30 2022 at 13:39):

and P has the right type


Last updated: Jul 15 2022 at 23:21 UTC