agda-stdlib icon indicating copy to clipboard operation
agda-stdlib copied to clipboard

Standardise record constructor names

Open mechvel opened this issue 4 years ago • 11 comments

For record IsGCD in Algebra.Divisibility, the constructor is gcdᶜ . But for some other records, the constructor is of kind mk<Foo>. Probably we need to make it uniform. Personally, I vote for . Because a) it abbreviates "constructor", b) it is shorter. ?

mechvel avatar Dec 30 '20 16:12 mechvel

A little crazy solution.

Currently field projections (destructors of coinductive types) are distingushed by postfix notation prefixed by dot like this: arg .fst , arg .snd

It would be lexically perfect if we were able to use a fully mirrored notation for constructors of inductive types like this: Left. arg , Right. arg - i.e. as prefix operator postfixed by dot.

As far as I'm aware none languages use this notation. I understand this should be a (questionable) request for agda repository, but here is the place where the discussion of constructors was started.

zraffer avatar Dec 30 '20 17:12 zraffer

Because a) it abbreviates "constructor"

I don't think the proposal is fully fledged. Is it:

  • Take a record type name that starts with Is
  • Drop the Is prefix
  • Make it lowercase
  • Append the character

?

b) it is shorter.

It's shorter by 1 character but it's more annoying to type.

gallais avatar Dec 30 '20 20:12 gallais

Not precisely. I mean

  1. Change the first letter in the record name to the lower case.
  2. Append the character ᶜ Example:
record IsGCD ... where
    constructor isGCDᶜ

Generally, <foo>ᶜ where <foo> is a name starting with a lower case symbol and having much in common with the record name.

b) it is shorter.

It's shorter by 1 character but it's more annoying to type.

But mkFoo looks like an ordinary function name, as not necessarily a record constructor.

mechvel avatar Dec 31 '20 07:12 mechvel

@mechvel thanks for raising this. I agree, we should be consistent about how we name the record constructors.

I'm with @gallais and that we should go with mk as a prefix to the record name. It's two easy characters to type "mk" rather than three, two of which are hard ones "^c".

I don't quite know what you mean by "it looks like an ordinary function name, as not necessarily a record constructor.". In Agda the set of valid names for record constructors and functions are identical?

MatthewDaggitt avatar Dec 31 '20 09:12 MatthewDaggitt

It is desirable to have a final decision announced.

mechvel avatar Dec 31 '20 11:12 mechvel

I don't quite know what you mean by "it looks like an ordinary function name, as not necessarily a record constructor.".

Seeing (fooᶜ x y ...) the reader would understand concretely that this is a record construction from the record fields. Seeing (mkFoo x y ...) the reader would imagine generally some function that makes something from something , for example, makes an instance of StrictTotalOrder from DecTotalOrder, Foo from Foo' ... The are many kinds of entities that can be made from other kinds of entities. This is a meaning tradition of the word mk. For mkFoo, the reader can think of Foo as of a record or of a relation or of other things. And fooᶜ has not such an indefinite tradition, it will be understood that Foo is a record. (?)

mechvel avatar Dec 31 '20 21:12 mechvel

In response to your comments in #1392 let's go with mk. I'l l add an entry to the style guide at some point.

MatthewDaggitt avatar Jan 07 '21 06:01 MatthewDaggitt

Bumping this to v2.0 as it will be breaking change.

MatthewDaggitt avatar Apr 09 '21 10:04 MatthewDaggitt

Bumping this to v2.0 as it will be breaking change.

Can't we use pattern synonyms to make it backwards compatible?

gallais avatar Apr 09 '21 10:04 gallais

Err, honestly I'm not sure. If you think there are no edge cases in which record constructors can be used and pattern synonyms cannot, then I'll believe you. However, we know there are such edge cases when using pattern synonyms to try and deprecate data constructors right?

MatthewDaggitt avatar Apr 09 '21 10:04 MatthewDaggitt

Right. If only we had typed pattern synonyms. :(

gallais avatar Apr 09 '21 11:04 gallais