2

Is there a way to define syntactic replacements for types in Isabelle/HOL?

I want to do something like this:

syntax my_short_list :: "type" ("my-list")
translations "my_short_list" ⇌ (type) "'a list"  ― ‹Could not find syntax to express this ...›

locale foo =
  fixes blub :: "my-list ⇒ my-list"

And want this to be interpreted like this:

locale foo =
  fixes blub :: "'a list ⇒ 'a list"

(all occurrences of my-list are replaced with the text 'a list)

The above produces the following error:

Error in syntax translation rule: rhs contains extra variables
"my_short_list" ↝ ("\<^type>List.list" 'a)

So I am looking for a variant that is a purely syntactic replacement without any macro hygiene checks.

Some background to understand the underlying problem:

I have a locale with 5 type parameters and a datatype X that takes all 5 type parameters, so for every use I have to write ('a, 'b, 'c, 'd, 'e) X. Obviously the names are longer in practice so this becomed even more unreadable.

Other approaches I tried:

  1. Defining the types or a type_synonym in my locale. This is not allowed (see https://stackoverflow.com/a/19281758/303637).
  2. Just using another type parameter to represent ('a, 'b, 'c, 'd, 'e) X and assumes for all the required properties of the data type. This is a lot of boilerplate since I need to write down all the properties that are usually automatically generated for datatype definitions.
Peter Zeller
  • 2,245
  • 19
  • 23

0 Answers0