[nem-en] Type inference in completion
Kamil Skalski
kamil.skalski at gmail.com
Thu May 3 09:37:17 CEST 2007
>
> As I can understand type inference first process lambda body and on it
> result make overloads resolution. But in case:
> x => x.|
> typer can't do assumptions about type of 'x'.
> I right?
> Maybe in this case try to make overloads resolution only on basis of
> arguments count and types of arguments which can be inferred?
Exactly. If you have 'map (x => x.foo)' then type inference first goes
deep into the lambda and it can see that:
- no special constraint is known about x
- no special constraint is known about lambda return type
- the whole lambda is ('a?) -> ?
And here the first step ends, since we cannot resolve types with these
constraints as they are. But then second pass goes and it tries to do
overloading of 'map' with what it has --> it compares possible
overloads, like map : (string -> V) -> list [V] with parameter type
'a? -> ?, so it adds contraints:
'a? === string
V === ?
and we have
- string constraint is known about x
- V constraint is known about lambda return type
- the whole lambda is string -> V
So now it runs again delyed typing of lambda body, and now it gets
that x.foo is resolved to something, basing of type of x
Finally V is constrained to the type of 'foo' in string
>
> And second question...
> How I can make hook on some identifier (object or member access) in order to
> get result of DelyedTyping?
I'm not sure... maybe it will be necessary to add special kind of
delyed typing to public class DelayedTyping (in Typer-DelayedTyping)
or extend existing MemberAccess { expr : TExpr; name : PT.Name; } one.
This however requires handling this additional node in the whole
complex logic of this file.
The place of interest for you would be method DoResolve () : void in
Typer-DelayedTyping where you would gather the information about x's
type then processing your additional node with MemberAccess (obj,
HalfId)... or something similar.
>
> > Maybe Michal could give you some more hints.
>
> It's will be nice.
>
> Vlad
>
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list