Operator overloading seems completely antithetical to what most seem to
value in Go. Readability is key. Go mostly avoids syntactic sugar (and
where it has it, it is often acknowledged as a mistake).
  To me, the existing contracts design makes it clear when a generic is
being used. It should also make for god's error reporting when a user, or
writer, of a generic type or function does not adhere to that contract.
  People seem to be trying to reduce line count, or minimize the visual
impact of generics. Why? I want big signposts warning me when it's in use.
On Wed, 17 Oct 2018, 11:13 alanfo, <alan.f...@gmail.com> wrote:

> On Wednesday, October 17, 2018 at 12:22:15 AM UTC+1, Patrick Smith wrote:
>>
>> On Tue, Oct 16, 2018 at 3:33 AM alanfo <alan...@gmail.com> wrote:
>>
>>> I would also disallow overloading of the =, :=, <-, ..., [], {}, () and
>>> yes - equality operators - as well because I believe to do otherwise would
>>> be very confusing.
>>>
>>
>> If overloading [] were disallowed, how would one write a generic function
>> taking a single argument of type either []int or a user-defined type with
>> similar behavior, and returning the sum of the elements? Sort of the
>> marriage of these two functions:
>>
>> func SumIntSlice(s []int) int {
>>
>> sum := 0
>>
>> for _, i := range s {
>>
>> sum += i
>>
>> }
>> return sum
>>
>> }
>>
>> type IntList interface {
>>
>> Len() int
>>
>> At(int) int
>>
>> }
>>
>> func SumIntList(l IntList) int {
>>
>> sum := 0
>>
>> for n := 0; n < l.Len(); n++ {
>>
>> sum += l.At(n)
>>
>> }
>>
>> return sum
>>
>> }
>>
>
>  I'm wobbling a bit on disallowing the overloading of the indexation
> operator following something Eric said in response to that.
>
> However, as long as the proposal includes the ability to overload
> conversions as well as operators (another point I made earlier), the
> example you gave could be dealt with by implementing a conversion to []int
> so you could then use all the latter's properties to code a common function.
>
> Alan
>
> --
> 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.
>

-- 
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