On Wed, Jan 20, 2021 at 3:24 AM Brian Candler <b.cand...@pobox.com> wrote:
>
> Yes.  Conceptually at least, interfaces defined as type lists could be used 
> as interfaces:
>
> type Foo interface { type int32, int64 }
> func f(a, b Foo) {
>     if (a < b) ...
> }
>
>  Without specialisation, there would be dynamic dispatch.  Internally it 
> might work something like
>
>     if (a.__lt__(b)) ...
>
> At worst the __lt__ function for int32 uses reflection to check its right 
> argument is int32.  However I believe go always requires that both arguments 
> to "<" are the same type, so the compiler itself can check that.  In the 
> above example this can be elided because it knows a and b are the same type; 
> at worst it adds a run-time check.

They are the same type, but that type is the interface type Foo.  We
can define equality on interface types, by saying that different
dynamic types are not equal.  But we can define a sensible ordering
type on interface types.  The closest we could come would be to panic
if you use `__lt__` on interface types that have different dynamic
types.  That could be done but seems unlikely to be useful.

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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXO6akVFk2y_qf%3D_MqUh%2Bs7EsVmG1CZUeSFk391f3TeFQ%40mail.gmail.com.

Reply via email to