Ian Lance Taylor
unread,Aug 3, 2019, 2:12:04 AM8/3/19Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Steven Blenkinsop, Axel Wagner, Bruno Albuquerque, golang-nuts
On Fri, Aug 2, 2019 at 9:25 PM Steven Blenkinsop <
stev...@gmail.com> wrote:
>
> On Fri, Aug 2, 2019 at 6:55 PM 'Axel Wagner' via golang-nuts <
golan...@googlegroups.com> wrote:
>>
>>
>> contract Comparable(T) {
>> T comparable, Equal(T) bool
>> }
>
>
> Wait, does this work? I mean, `comparable` is a contract, but it's being used as a constraint.
You're right, I wrote it wrong. Actually I'm not sure how to write
that contract. Ideally we want to say that T is either comparable or
has the Equal(T) bool method, but there is no way to write that. We
can embed comparable(T), but we can't do that in a disjunction with
Equal(T) bool.
> The same issue comes up with the
>
> switch T.(type) { ... }
>
> idea. Even if you're only constraining one type at a time like this, you might still need to express a relationship to another type parameter. Unless this is allowed:
>
> switch (type) {
> case comparable(T): ...
> case Equaler(T): ...
> }
I suspect that switch T.(type) would have to only permit disjunctions
listed in the contract for T.
Ian