1

Two classes are defined containing the same function, but when the two classes is used in a locale there is an unification error:

theory Scratch
imports Main 
begin


  class c1 =
    fixes getName :: "'a ⇒ string"

  class c2 =
    fixes getName :: "'a ⇒ string"

  locale c12 = 
    fixes match :: "('a::c1) ⇒ ('b::c2) ⇒ bool"
    assumes as : "match a b ⟶ (getName a) = (getName b)"

end

The unification error is resolved by renaming (getName b) to (getName_b b) and use the class definition

  class c2 =
    fixes getName_b :: "'a ⇒ string"

Does a solution exist without renaming?

Here a solution is given when the overloading is needed when datatypes are parameters.

Community
  • 1
  • 1
Johan
  • 575
  • 5
  • 21

1 Answers1

2

Fully or partially qualified identifiers can be used. I used find_consts, as shown below, to find the qualified names of the type class constants.

The type inference only required that I use c1_class.getName a to get rid of the error.

theory Scratch
imports Complex_Main
begin
class c1 =
  fixes getName :: "'a => string"

class c2 =
  fixes getName :: "'a => string"

find_consts name: getName (*
  find_consts
  name: "getName"

  found 2 constant(s):
    Scratch.c1_class.getName :: "'a => char list"
    Scratch.c2_class.getName :: "'a => char list"
*)

declare[[show_sorts]]
locale c12 = 
  fixes match :: "('a::c1) => ('b::c2) => bool"
  assumes as : "match a b --> (c1_class.getName a) = (getName b)"

end