[generics] why struct fields-based constraints were banned?

229 views
Skip to first unread message

Denis Cheremisov

unread,
Jun 17, 2020, 1:04:16 PM6/17/20
to golang-nuts
I can't get why struct based constraints were banned. struct is a kind of types in Go and a wish to only allow them having some field is valid. 

Ian Lance Taylor

unread,
Jun 17, 2020, 8:18:05 PM6/17/20
to Denis Cheremisov, golang-nuts
On Wed, Jun 17, 2020 at 10:05 AM Denis Cheremisov
<denis.ch...@gmail.com> wrote:
>
> I can't get why struct based constraints were banned. struct is a kind of types in Go and a wish to only allow them having some field is valid.

I'm not sure I would say that they were banned, it's just that we
haven't seen a good way to fit them into the notion of interface types
as constraints.

It's not clear how important this is. It's not clear how often this
really comes up in practice.

Ian

Bryan C. Mills

unread,
Jun 17, 2020, 11:04:53 PM6/17/20
to golang-nuts
I could imagine a new kind of interface type specifying fields (not just methods), with the offsets of the corresponding fields in the concrete type stored in the interface's type descriptor.

(I think such a feature would be orthogonal to the current design draft, and could be proposed separately as a followup.)

Denis Cheremisov

unread,
Jun 18, 2020, 4:44:44 PM6/18/20
to golang-nuts
It would be much less troublesome if you would keep using contracts instead of this interface insanity.

четверг, 18 июня 2020 г., 3:18:05 UTC+3 пользователь Ian Lance Taylor написал:

Ian Lance Taylor

unread,
Jun 18, 2020, 6:29:48 PM6/18/20
to Denis Cheremisov, golang-nuts
On Thu, Jun 18, 2020 at 1:45 PM Denis Cheremisov
<denis.ch...@gmail.com> wrote:
>
> It would be much less troublesome if you would keep using contracts instead of this interface insanity.

I understand that you are not in favor of the new design draft, but
some of the words you are using are on the aggressive side. Please be
mindful of our code of conduct (https://golang.org/conduct) and
express your disagreement in more respectful ways. We are all working
to make Go better.

Thanks.

Ian
Reply all
Reply to author
Forward
0 new messages