Re: [go-nuts] Generics - Min challenge

2018-09-14 Thread Jesper Louis Andersen
On Wed, Sep 12, 2018 at 4:49 PM Wojciech S. Czarnecki wrote: > > This is not metaprogramming! > > Every and each statement is written by the human author in plain Go > and no code is produced by the program itself. > > The key of metaprogramming is the ability to treat code as data which can be m

Re: [go-nuts] Generics - Min challenge

2018-09-14 Thread Wojciech S. Czarnecki
[Bcc: drchase] On Wed, 12 Sep 2018 10:55:26 +0200 "Wojciech S. Czarnecki" wrote: > func Min(a, b T) T { `func Min(a, b type T) type T` of course. Late correction but needed. > for type switch { > case T func(T) Less(T) T: > return a.Less(b) > } > if a < b { >return a >

Re: [go-nuts] Generics - Min challenge

2018-09-14 Thread Wojciech S. Czarnecki
On Thu, 13 Sep 2018 10:29:21 -0700 (PDT) Manlio Perillo wrote: > `try` tries each block at compile time, and use the first block that > compiles successfully. How the reader of this will know what will compile and what not? Esp doing "by a finger"/"paper and pencil" codewalk?. But you just red

Re: [go-nuts] Generics - Min challenge

2018-09-13 Thread Manlio Perillo
On Wednesday, September 12, 2018 at 10:56:04 AM UTC+2, ohir wrote: > > On Tue, 11 Sep 2018 18:22:12 -0700 > Patrick Smith > wrote: > > > I'm fairly sure there's no way to write Min, but perhaps someone can > prove > > me wrong? > > Within "Craftsman Go Generics" proposal its trivial: > > func

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Wed, 12 Sep 2018 10:05:06 -0700 Ian Lance Taylor wrote: > a compile-time decision as to which code should be compiled. Note that this decision making is needed only for outstanding cases usually in user own code. For many generic implementation a simple for type contract is enough: // Sum met

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Wed, 12 Sep 2018 10:05:06 -0700 Ian Lance Taylor wrote: > I agree that no code is produced by the program, but you're suggesting > a compile-time decision as to which code should be compiled. How does it differ from unused code eliding go compiler and linker do already? Used `for type case`

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Patrick Smith
On Wed, Sep 12, 2018 at 6:34 AM Ian Lance Taylor wrote: > That said, if we move forward with something like contracts, I think > that it may be possible to introduce contract adaptors in the future: > a mechanism that says "if the type argument does not implement > contract C1, but does implement

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Michael Jones
Compile-time logic feels like a baby/bathwater issue to me. With M4 and then CPP on the scene, new kinds of adaptable code became possible in C. It was such a compelling benefit (I still have the CSTRs) that it grew to ubiquity and finally to a monsterous horror in C++ that in recent decades, thro

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Ian Lance Taylor
On Wed, Sep 12, 2018 at 7:49 AM, Wojciech S. Czarnecki wrote: > On Wed, 12 Sep 2018 06:33:59 -0700 > Ian Lance Taylor wrote: > > Addenum: > >> You need to have a way to say "compile this code under certain >> conditions based on the type argument, otherwise compile this code." >> That is, the co

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Wed, 12 Sep 2018 07:40:37 -0700 Ian Lance Taylor wrote: > The difference I see is that in one case we write code that can not be > compiled, and then tell the compiler not to compile it. > we direct the compiler to automatically insert wrappers that > make the type fit the contract. Who is s

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Wed, 12 Sep 2018 06:33:59 -0700 Ian Lance Taylor wrote: Addenum: > You need to have a way to say "compile this code under certain > conditions based on the type argument, otherwise compile this code." > That is, the compiler is directed, at compile time, as to which code > should be compiled

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Ian Lance Taylor
On Wed, Sep 12, 2018 at 7:32 AM, Wojciech S. Czarnecki wrote: > On Wed, 12 Sep 2018 06:33:59 -0700 > Ian Lance Taylor wrote: > >> I don't think there is any way to solve this problem as stated without >> taking a step toward metaprogramming: making decisions at compile time. > > Excuse me, how an

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Wed, 12 Sep 2018 06:33:59 -0700 Ian Lance Taylor wrote: > I don't think there is any way to solve this problem as stated without > taking a step toward metaprogramming: making decisions at compile time. Excuse me, how and where below stated artificial "contract adaptors" are NOT "making decis

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Ian Lance Taylor
On Tue, Sep 11, 2018 at 6:22 PM, Patrick Smith wrote: > > This is a hypothetical question. Suppose generics were implemented as in the > draft proposal, but without contracts. Instead, the rule is that if an > instantiation of a generic function with a specific type argument doesn't > compile, the

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread 'Axel Wagner' via golang-nuts
ISTM that your requirements can't work. 2) and 3) imply that the expression `x < y` with x,y of type T has to appear at least once in the function body, which means it can never work for a type that doesn't have it. I don't think that has anything to do with changing the type-checking rules though

Re: [go-nuts] Generics - Min challenge

2018-09-12 Thread Wojciech S. Czarnecki
On Tue, 11 Sep 2018 18:22:12 -0700 Patrick Smith wrote: > I'm fairly sure there's no way to write Min, but perhaps someone can prove > me wrong? Within "Craftsman Go Generics" proposal its trivial: func Min(a, b T) T { for type switch { case T func(T) Less(T) T: return a.Less(b) }

[go-nuts] Generics - Min challenge

2018-09-11 Thread Patrick Smith
This is a hypothetical question. Suppose generics were implemented as in the draft proposal, but without contracts. Instead, the rule is that if an instantiation of a generic function with a specific type argument doesn't compile, then it can't be used. Under those circumstances, is there any way