On Tue, Jul 14, 2020 at 11:06 PM Bakul Shah <ba...@iitbombay.org> wrote: > > I don't much like square brackets or angle brackets or guillemets. But here > is a different way > of reducing the need for parentheses at least for the common case: > > A proposal for fewer irritating parentheses! > > One thing to note is that generic functions & types are *different* from > existing things like const, func, type, var. As such they should have their > own declaration marker. For example > > gen T type pair struct { a, b T } // contrast with type pair(type T) ... > gen T,U type W struct { a T; b U } // contrast with type W(type T, U) ... > gen T func Print(s []T) {...} // print a slice of T > > These function/type/method generics are used by *prepending* the type: > > var x int pair // a pair of ints > var y (int, int pair) W // here we have to use parentheses > int Print([]int{1,2,3}) // print a slice of ints > qq := int pair pair{{1,2},{3,4}} // a pair of a pair of ints > ww := (int, int) W pair{{1,2},{3,4}} > > This use may seem weird if you are used to C/C++. I find it more readable > than having to deal with extra parentheses. "int pair" clearly says a > pair of ints and so on. What is more, if in future types are allowed to be > *inferred* for generic function calls, you can simply drop the type prefix. > > If there is still a parsing ambiguity, I'd suggest adding a - as in int-pair. > > Additional type syntax rule: > > type: ... | type generic-type| (type-list) generic-type > > or > > type: ... | type "-" generic-type | (type-list) "-" generic-type > > FWIW I thought of this four weeks ago (June 16).
Thanks for the note. It's an interesting idea, but I'm not quite sure it works to have prefix types with no real delimiters. It may work to write "int pair pair" but does it work to write "func() int pair pair"? That is the type of a pair of functions where each function returns the type "int pair". If we have to start carefully deciding where we need to add parentheses then I'm not sure we've gained very much by switching to this kind of syntax. 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/CAOyqgcWf8KaJdHgq2fccEAZU_KNAx92G--VvEeJT-fr2ZMCnbw%40mail.gmail.com.