Skip to content

spec: "strictly comparable" and "type constraints". #59104

@gitspeaks

Description

@gitspeaks

#1 According to the Language Specification:

A type is strictly comparable if it is comparable and not an interface type nor composed of interface types. Specifically:

Boolean, numeric, string, pointer, and channel types are strictly comparable.
Struct types are strictly comparable if all their field types are strictly comparable.
Array types are strictly comparable if their array element types are strictly comparable.
Type parameters are strictly comparable if all types in their type set are strictly comparable."

Consider changing to:

A type is strictly comparable if it is comparable and not a basic interface type nor composed of 
interface types. Specifically: 

Boolean, numeric, string, pointer, and channel types are strictly comparable. 
Struct types are strictly comparable if all their field types are strictly comparable. 
Array types are strictly comparable if their array element types are strictly comparable. 

Type constraints are strictly comparable if their elements are strictly comparable thus 
Type parameters (not to be confused with Type arguments) are strictly comparable if all 
types in their type set are strictly comparable. 

Rational: By definition “A type constraint is an interface” and the doc explicitly mentions: “strictly comparable type constraint” under "Satisfying a type constraint".

#2 Consider capitalizing each instance of the word "Comparable" where it references the property of comparability, as described in the "Comparison Operators" section. The term "comparable" appears in other contexts, such as "strictly comparable" and the comparable Interface", so due to the repetition of the word, it can be difficult to follow.

#3 Addressing a related but distinct issue, under "General Interfaces" it is stated that: "The type set of a non-interface type term is the set consisting of just that type."

The following example is provided:

// An interface representing only the type int 
type Foo interface { int }

By definition, this interface is a non-basic interface, which means it can only appear in type constraints. However, the rationale for an interface of this form is not immediately apparent. Please clarify in the spec the circumstances in which declaring an interface with a non-interface type term would be sensible.

Metadata

Metadata

Assignees

Labels

DocumentationIssues describing a change to documentation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions