On Fri, Aug 2, 2019 at 9:25 PM Steven Blenkinsop <[email protected]> wrote:
>
> On Fri, Aug 2, 2019 at 6:55 PM 'Axel Wagner' via golang-nuts
> <[email protected]> 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
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcW79egVQJ1aDe9YpMYEs1E8y3F4yfcFnJQx13Khxyvx2g%40mail.gmail.com.