i.e not a list containing possibly eg. type literals/anonymous types.
I don't think so. The type list in this case is syntactically just an identifier list, i.e not a list containing possibly eg. type literals/anonymous types.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/48c0d6fb-16ce-4495-b520-d4a28166c122n%40googlegroups.com.
I think in the overwhelmingly common case (a type-list being a list of identifiers or short type-constructors like channels or slices), having a line per item takes up a lot of vertical real-estate for little use.
axel.wa...@googlemail.com schrieb am Dienstag, 18. August 2020 um 17:44:16 UTC+2:I think in the overwhelmingly common case (a type-list being a list of identifiers or short type-constructors like channels or slices), having a line per item takes up a lot of vertical real-estate for little use.Both options, single line and multi-line, are still available with curly braces and semicolons
, but in the multi-line case you do not have to manage trailing commas, and the first line containing type(s) is not indented differently than the following lines.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b2cfd94c-50d0-48df-b371-b018c08b4a23n%40googlegroups.com.
1. `anyof` declarations, only usable as types
2. `interface` declarations containing only methods, usable as constraints and types
3. `interface` declarations containing methods and type-lists ("embedded `anyof`s), only usable as constraint.
I agree it is a weird combination. Ideally it would be:1. `anyof` declarations containing only types, usable as constraints and types2. `interface` declarations containing only methods, usable as constraints and types3. n/aBut then Go would introduce both generics and sum types at the same time, which does not seem to be feasible due to unsolved questions like the zero-value issue.
The more I think about it the less I understand why type list should reside inside interfaces. I can only think of two reasons:1) Avoid a new keyword for type lists.
2) The idea that only interfaces should be able to act as constraints.
Regarding 2): Why this artificial limitation? Why not allow all types as constraints? Even int. It's nonsensical, but it would be like "interface{ type int }" in the current draft, which is nonsensical, too.
The rule would be simple: Any type can act both as normal type and as constraint. With the possible exception of `anyof`s, until there is a solution to use them as regular types as well.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/8711bcf9-6ebe-4014-9034-d0a642078791n%40googlegroups.com.
We already have a way to express "any of a certain subset of types", which are interfaces, so using them for constraints is natural.
it's about avoiding a new *concept*.
No, it is neither the same, nor is it nonsensical. `interface{ type int }` is any type with *underlying type* `int`, not just `int`. It adds some expressive power. I'm not sure how important that expressive power is, but it's more than zero.
I'd argue that every type expresses a certain subset of types, not just interfaces. For the other types the size of the subset just happens to be 1 (each containing just itself).
Type lists are still a new concept. Just because they hide inside interfaces doesn't mean that they are not a new concept.
On the go2go.dev branch they recently made a change to use the actual (not underlying) types of type list elements for interface satisfaction: https://github.com/golang/go/commit/af48c2e84b52f99d30e4787b1b8d527b5cd2ab64
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/96914146-3f4e-4972-a18a-3d6b957acb90n%40googlegroups.com.
What would it mean to permit any type as a constraint?
I actually looked into this, to see if we could say that any type
could be used as a constraint, and say that a type parameter
constraint would permit any type argument that is assignable to the
constraint type. Unfortunately that leads to some odd behavior. If
we use a named type as the constraint, it may have methods. But we
can use a corresponding type literal as a type argument. That would
add methods to a type literal with no explicit type conversion.
Similarly, if we use a type literal as a type, we can use a defined
type as a type argument. But the generic function could assign the
type parameter to some other defined type, and now we have a generic
function that could not be compiled if we simply substituted the type
argument for any instance of the type parameter.
And I don't see what we gain by following that path.
Yes, but here you are assigning the value struct{}{} to the type S.
That's not how type arguments work: type arguments are not assigned to
type parameters. Instead, the body of a generic function or type is
instantiated with the type argument. In a generic function, rather
than assigning a value struct{}{} to type S, we are replacing
instances of S in F with struct{}. But struct{} has no methods. So
can you call method M on an argument whose type is the type parameter?
Why or why not?