On Thu, Oct 18, 2018 at 2:02 PM Ian Denhardt <i...@zenhack.net> wrote: > > Quoting robert engels (2018-10-18 15:22:36) > > Can you explain this a bit more, I must be missing something. Using the > > example: > > > > func F(a,b type T like(int,X)) { > > if a<b { > > ... > > } > > } > > > > How do you pass a struct to F because < isn’t valid on structs ??? > > > > Which is why I proposed that < maps to Less() and then the primitives > > simplicity implement these various methods, and user defined structs MIGHT. > > > > That way you write the code using Less(), and it works with primitives as > > well. > > This is what I was getting at; simply making the operators correspond to > methods is a well-known and fairly straightforward solution to the > problem, and it seems like the idea proposed in this thread is much more > complex. > > Once you allow operators to simply correspond to methods, you can just > worry about how to abstract over methods, which you can do with > interfaces. My proposal outlines a variant of this that is fairly > simple, yet (once adding something like operator overloading) is still > able to handle every single example in the draft. > > You can either give the primitive types methods, or allow methods to > override operators; both approaches work. > > Burak, apologies if I've misinterpreted your own line of thinking.
You did not misinterpret what I said. I agree that your proposal is quite similar to mine. One crucial difference between the two is, I think, my line of thinking is based on templates, and yours is on interfaces. So using my approach, you can require that a type contains certain members, not just methods. I don't know how important that is, but after working with Java for many years, I developed a strong dislike for getter/setters. > > -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. > 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.