Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-05 Thread roger peppe
On Mon, 5 Nov 2018 at 10:21, Axel Wagner wrote: > Even though all we did was save some references to values, the code has >> radically changed (along with its runtime implications). >> > > you'd choose a suitable small subset based on the type-constructors used > in the signature. > For the

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-05 Thread 'Axel Wagner' via golang-nuts
> > Even though all we did was save some references to values, the code has > radically changed (along with its runtime implications). > Because I am lazy and simply trying to illustrate how this can be done. I was trying to achieve consensus, not to implement generics and I never pretended that

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-05 Thread roger peppe
On Mon, 5 Nov 2018 at 02:35, Axel Wagner wrote: > On Sun, Nov 4, 2018 at 10:14 PM roger peppe wrote: > >> This code, for example: https://play.golang.org/p/eaLHBbUJT-d >> What might your generated code look like for that? >> > > A bit ad-hoc, but WAI: https://play.golang.org/p/vuCHY2RRxIR > >

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-04 Thread 'Axel Wagner' via golang-nuts
On Sun, Nov 4, 2018 at 10:14 PM roger peppe wrote: > Perhaps you might want to have a go at trying to translate a slightly more > substantial piece of generic code. For example, this generic implementation > of Dijkstra's algorithm: https://play.golang.org/p/BsktFSFVU0D. I'd be > interested to

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-04 Thread 'Axel Wagner' via golang-nuts
On Sun, Nov 4, 2018 at 10:14 PM roger peppe wrote: > This code, for example: https://play.golang.org/p/eaLHBbUJT-d > What might your generated code look like for that? > A bit ad-hoc, but WAI: https://play.golang.org/p/vuCHY2RRxIR In practice, of course, most of these wouldn't be actually

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-04 Thread roger peppe
hOn Sun, 4 Nov 2018 at 12:09, Axel Wagner wrote: > On Sun, Nov 4, 2018 at 11:45 AM roger peppe wrote: > >> One thing to consider: at any point in your program, someone might call >> something like the following function with any value in scope: >> >>var vals []interface{} >>func save(x

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-04 Thread 'Axel Wagner' via golang-nuts
On Sun, Nov 4, 2018 at 11:45 AM roger peppe wrote: > One thing to consider: at any point in your program, someone might call > something like the following function with any value in scope: > >var vals []interface{} >func save(x interface{}) { >vals = append (vals, x) >} > >

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-11-04 Thread roger peppe
One thing to consider: at any point in your program, someone might call something like the following function with any value in scope: var vals []interface{} func save(x interface{}) { vals = append (vals, x) } For the semantics of the generic program to be consistent, the values

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-25 Thread 'Axel Wagner' via golang-nuts
Sorry, should've added what I consider the source: https://play.golang.org/p/3_um7p3IxwK On Thu, Oct 25, 2018 at 10:09 AM Axel Wagner wrote: > Sure: https://play.golang.org/p/W_ruqI22Vhv > Seems a fairly straight-forward transformation to me - and again easy to > devirtualize. > > On Thu, Oct

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-25 Thread 'Axel Wagner' via golang-nuts
Sure: https://play.golang.org/p/W_ruqI22Vhv Seems a fairly straight-forward transformation to me - and again easy to devirtualize. On Thu, Oct 25, 2018 at 8:56 AM roger peppe wrote: > > On Thu, 25 Oct 2018, 12:52 am Axel Wagner, > wrote: > >> On Thu, Oct 25, 2018 at 12:39 AM roger peppe

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-25 Thread roger peppe
On Thu, 25 Oct 2018, 12:52 am Axel Wagner, wrote: > On Thu, Oct 25, 2018 at 12:39 AM roger peppe wrote: > >> I understand this argument. By putting some smarts into the compiler, we >> would hope that we can see benefits not just in our generated generic code, >> but also in other code that

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-24 Thread 'Axel Wagner' via golang-nuts
On Thu, Oct 25, 2018 at 12:39 AM roger peppe wrote: > I understand this argument. By putting some smarts into the compiler, we > would hope that we can see benefits not just in our generated generic code, > but also in other code that we've already written that uses generics. This > would be

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-24 Thread roger peppe
On Sun, 21 Oct 2018 at 13:53, Axel Wagner wrote: > Last addition: > > On Sun, Oct 21, 2018 at 2:03 PM roger peppe wrote: > >> Ah, I *think* I see where you might be coming from now. You're thinking >> that the compiler could do some kind of Go-to-Go transformation for generic >> functions so

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-24 Thread roger peppe
On Sun, 21 Oct 2018 at 13:40, Axel Wagner wrote: > On Sun, Oct 21, 2018 at 2:03 PM roger peppe wrote: > >> Yes. The draft proposal says "generic functions, rather than generic >> types, can probably be compiled using an interface-based approach. That >> will optimize compile time, in that the

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-21 Thread 'Axel Wagner' via golang-nuts
Last addition: On Sun, Oct 21, 2018 at 2:03 PM roger peppe wrote: > Ah, I *think* I see where you might be coming from now. You're thinking > that the compiler could do some kind of Go-to-Go transformation for generic > functions so that they looked exactly as if they'd been written using >

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-21 Thread 'Axel Wagner' via golang-nuts
On Sun, Oct 21, 2018 at 2:03 PM roger peppe wrote: > Yes. The draft proposal says "generic functions, rather than generic > types, can probably be compiled using an interface-based approach. That > will optimize compile time, in that the package is only compiled once, but > there will be some

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-21 Thread roger peppe
On Sat, 20 Oct 2018 at 11:37, Axel Wagner wrote: > > Thank, I feel I can work with this :) > > On Sat, Oct 20, 2018 at 10:58 AM roger peppe wrote: > >> That transformation might be valid for the simple case you have there, >> where there's a single parameter of exactly the interface type, but

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-20 Thread 'Axel Wagner' via golang-nuts
Thank, I feel I can work with this :) On Sat, Oct 20, 2018 at 10:58 AM roger peppe wrote: > That transformation might be valid for the simple case you have there, > where there's a single parameter of exactly the interface type, but generic > functions allow much more than that. You can have

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-20 Thread roger peppe
On Fri, 19 Oct 2018 at 22:41, Axel Wagner wrote: > As I said, I don't really understand why we disagree here - or what we are > even disagreeing about. So let me make my claim as precise as possible, in > the hope that it at least helps me understand which particular part you are > disagreeing

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-19 Thread 'Axel Wagner' via golang-nuts
As I said, I don't really understand why we disagree here - or what we are even disagreeing about. So let me make my claim as precise as possible, in the hope that it at least helps me understand which particular part you are disagreeing with. I claim: a) w.l.o.g. we can ignore operators

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-19 Thread roger peppe
On Fri, 19 Oct 2018 at 12:04, roger peppe wrote: > The algorithm to do it is quite straightforward: > https://play.golang.org/p/subnLkSSxdI > On reflection, that ParamType hack won't work correctly with types.Identical. This should work better: https://play.golang.org/p/iswgf7mr8ht > -- You

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-19 Thread roger peppe
On Thu, 18 Oct 2018 at 13:41, Axel Wagner wrote: > On Thu, Oct 18, 2018 at 2:06 PM roger peppe wrote: > >> For generics, that analysis is trivial - there is no need to do any >> control flow analysis to determine the set of possible generic type >> parameters to a type or function (with the

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-18 Thread 'Axel Wagner' via golang-nuts
On Thu, Oct 18, 2018 at 2:06 PM roger peppe wrote: > For generics, that analysis is trivial - there is no need to do any > control flow analysis to determine the set of possible generic type > parameters to a type or function (with the exception of recursive generic > functions, which can be

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-18 Thread roger peppe
On Thu, 18 Oct 2018 at 08:40, Axel Wagner wrote: > On Thu, Oct 18, 2018 at 9:16 AM roger peppe wrote: > >> The difference is that for generics, you *always* know the exact set of >> possible types that a type parameter can be. >> > > If and only if you choose to do that analysis. AFAIK it is

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-18 Thread 'Axel Wagner' via golang-nuts
On Thu, Oct 18, 2018 at 9:16 AM roger peppe wrote: > The difference is that for generics, you *always* know the exact set of > possible types that a type parameter can be. > If and only if you choose to do that analysis. AFAIK it is not currently planned to do that

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-18 Thread roger peppe
On Thu, 18 Oct 2018 at 06:44, Axel Wagner wrote: > This is only tangentially related to your specific idea, but I've decided > that for generics discussions this is the hill I'm dying on: > > On Wed, Oct 17, 2018 at 6:44 PM roger peppe wrote: > >> The method calls in question can be inlined

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-17 Thread 'Axel Wagner' via golang-nuts
This is only tangentially related to your specific idea, but I've decided that for generics discussions this is the hill I'm dying on: On Wed, Oct 17, 2018 at 6:44 PM roger peppe wrote: > The method calls in question can be inlined because everything is known > statically, so there's

Re: [go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-17 Thread Ian Denhardt
I don't think you even need contracts as such at this point; you can do a cast without them, so you just need to be able to specify a method set on type parameters. I would be interested to hear your thoughts on the proposal I wrote up on how to do this:

[go-nuts] relaxing type conversions: an "almost possible" idea with Go generics

2018-10-17 Thread roger peppe
While thinking about the draft generics proposal and the complexity of contracts, it occured to me that if you relax some of the restrictions on type conversion, it's possible to make data structures containing basic types amenable to generic algorithms. Once upon a time, the Go specification