Re: Idea: Reverse Type Inference

2017-06-05 Thread Steven Schveighoffer via Digitalmars-d
On 6/3/17 7:37 PM, Enamex wrote: On Wednesday, 24 May 2017 at 15:02:05 UTC, Steven Schveighoffer wrote: In fact, you could simulate overloading of return values based on IFTI instantiation: void fooImpl(ref int retval, int x) { ... } void fooImpl(ref string retval, int x) { ... } T foo(T)(int

Re: Idea: Reverse Type Inference

2017-06-03 Thread Enamex via Digitalmars-d
On Wednesday, 24 May 2017 at 15:02:05 UTC, Steven Schveighoffer wrote: In fact, you could simulate overloading of return values based on IFTI instantiation: void fooImpl(ref int retval, int x) { ... } void fooImpl(ref string retval, int x) { ... } T foo(T)(int x) { T t; fooImpl(t, x); return t

Re: Idea: Reverse Type Inference

2017-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/24/17 10:58 AM, Steven Schveighoffer wrote: On 5/24/17 10:28 AM, Ola Fosheim Grøstad wrote: Ok, well, I see templates in this context as a variation of overloading, just with the template parametric type being a set of types i.e. all types that the program provides, minus the ones prevented

Re: Idea: Reverse Type Inference

2017-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/24/17 10:28 AM, Ola Fosheim Grøstad wrote: On Wednesday, 24 May 2017 at 13:03:37 UTC, Steven Schveighoffer wrote: This is different. It's IFTI based on return type. Well, the way I see it it is a special case of top-down type inference. Yes, you also have to instantiate the template, but

Re: Idea: Reverse Type Inference

2017-05-24 Thread Ola Fosheim Grøstad via Digitalmars-d
On Wednesday, 24 May 2017 at 13:03:37 UTC, Steven Schveighoffer wrote: This is different. It's IFTI based on return type. Well, the way I see it it is a special case of top-down type inference. Yes, you also have to instantiate the template, but I assume that happens after type inference is c

Re: Idea: Reverse Type Inference

2017-05-24 Thread Steven Schveighoffer via Digitalmars-d
On 5/23/17 5:20 AM, Ola Fosheim Grøstad wrote: On Monday, 22 May 2017 at 10:13:02 UTC, Sebastiaan Koppe wrote: Over the past weeks I have been noticing a specific case where it happens. I call it reverse type inference, simply because it goes against the normal evaluation order. I think what y

Re: Idea: Reverse Type Inference

2017-05-23 Thread Timon Gehr via Digitalmars-d
On 23.05.2017 16:55, Petar Kirov [ZombineDev] wrote: On Monday, 22 May 2017 at 13:39:46 UTC, Timon Gehr wrote: ... Another annoying case: alias Fun(A,B) = B delegate(A); B apply(A,B)(Fun!(A,B) f, A a){ return f(a); } void main(){ apply(x=>x,2); // error } Interesting. BTW, what do you t

Re: Idea: Reverse Type Inference

2017-05-23 Thread via Digitalmars-d
On Monday, 22 May 2017 at 13:39:46 UTC, Timon Gehr wrote: On 22.05.2017 12:13, Sebastiaan Koppe wrote: I work with Scala professionally. I often feel its type inference for generics/templates is better than D's; as long as it can find a type _anywhere_ it will use that, no matter where it needs

Re: Idea: Reverse Type Inference

2017-05-23 Thread Ola Fosheim Grøstad via Digitalmars-d
On Monday, 22 May 2017 at 10:13:02 UTC, Sebastiaan Koppe wrote: Over the past weeks I have been noticing a specific case where it happens. I call it reverse type inference, simply because it goes against the normal evaluation order. I think what you want, in the general sense, is basically ov

Re: Idea: Reverse Type Inference

2017-05-22 Thread bachmeier via Digitalmars-d
On Monday, 22 May 2017 at 13:20:41 UTC, Stefan Koch wrote: And how long does that code take to compile ? +1 My immediate thought was one of horror - Scala's compilation times are a sufficient reason to avoid the language. I also think it would make D code harder to read. Not a problem in

Re: Idea: Reverse Type Inference

2017-05-22 Thread Guillaume Boucher via Digitalmars-d
On Monday, 22 May 2017 at 13:20:41 UTC, Stefan Koch wrote: type inference is not magic, it's a search for a pattern over the syntax (sub)tree. Hence it can have quadratic time/memory complexity. Well, the type system of Scala is turing complete, hence it can take arbitrarily long: https://mi

Re: Idea: Reverse Type Inference

2017-05-22 Thread Timon Gehr via Digitalmars-d
On 22.05.2017 12:13, Sebastiaan Koppe wrote: I work with Scala professionally. I often feel its type inference for generics/templates is better than D's; as long as it can find a type _anywhere_ it will use that, no matter where it needs to pull it from. Over the past weeks I have been noticing

Re: Idea: Reverse Type Inference

2017-05-22 Thread Stefan Koch via Digitalmars-d
On Monday, 22 May 2017 at 10:13:02 UTC, Sebastiaan Koppe wrote: I work with Scala professionally. I often feel its type inference for generics/templates is better than D's; as long as it can find a type _anywhere_ it will use that, no matter where it needs to pull it from. And how long does t

Re: Idea: Reverse Type Inference

2017-05-22 Thread Moritz Maxeiner via Digitalmars-d
On Monday, 22 May 2017 at 10:13:02 UTC, Sebastiaan Koppe wrote: I work with Scala professionally. I often feel its type inference for generics/templates is better than D's; as long as it can find a type _anywhere_ it will use that, no matter where it needs to pull it from. Over the past weeks