[Issue 9022] IFTI should support enclosing type/scope deduction

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 17 05:01:59 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9022


timon.gehr at gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr at gmx.ch


--- Comment #5 from timon.gehr at gmx.ch 2012-11-17 05:01:56 PST ---
(In reply to comment #2)
> (In reply to comment #0)
> 
> > However, it will
> > introduce an IFTI order dependency between function parameters.
> 
> What are the difficulties or the dangers of introducing an IFTI order
> dependency between function arguments?

No introduction of order dependency is necessary. IFTI would have to become a
fixed-point seeking inference algorithm. But it really should anyways, eg.
[1,2,3,4].map(a=>a*2), should work, where 'map' is generic.
(map(a=>a*2,[1,2,3,4]) should work too).

The difficulty lies in formalizing and implementing the semantics of IFTI,
delegate parameter and return type deduction and template default arguments
precisely.

Eg:

auto foo(Z=int,A,B,C)(A delegate(Z) x, B delegate(A) y, C delegate(B) z){ ... }
foo(x=>x, y=>y+1.0f, z=>[1,2,z]);

should instantiate

foo!(int, int, float, float[])

I'd suggest:

1: Infer delegate/function pointer parameter types and full types of everything
else until a fixed point is reached.
2: Infer delegate return types where possible.
3: Repeat 1, 2 until a fixed point is reached
4: Resolve template default arguments that are independent of unresolved
arguments
5: Repeat 3, 4 until a fixed point is reached 
6: Check if all arguments have been found.

The split of 1 and 2 is not strictly necessary but it would make an
implementation of some kind of type unification simpler in the future.

Also taking into account curried delegates would improve the process further,
eg:

auto foo(T)(T delegate (T) delegate (T) dg);
foo(x=>(int y)=>x+y);

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list