I'm wrong about `==` here, because it's defined for interface values. 
`comparable` could be an interface.

But it won't work for other operators like `<` or `+`.

On Sunday, September 9, 2018 at 2:49:26 PM UTC-4, Jonathan Amsterdam wrote:
>
> FWIW, in my pseudo-interface description 
>> <https://blog.merovius.de/2018/09/05/scrapping_contracts.html> ...
>>
>
> You mention that comparable is a pseudo-interface, which means the type 
> supports the == and != operators. You say that comparable and the other 
> pseudo-interfaces are types.
>
> So I should be able to write a function like
>
>   func f(x, y comparable) bool { return x == y }
>
> And of course I can call it like so:
>
>    var x int
>    var y float32
>    f(x, y)
>
> The problem is that this program seems to type-check, but it is invalid. 
> The == operator is specified to work on operands of the same type, and it 
> is being used on operands of different types.
>
> This is the fundamental problem with using interfaces for operators.
>
> And since we need some operators for generics (at least == and <), it is 
> also one of the fundamental problems with unifying interfaces and contracts.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to