[haXe] Type inferrence problem
Nicolas Cannasse
ncannasse at motion-twin.com
Tue Aug 1 21:31:01 CEST 2006
> Hello list,
>
> I've found a small example where type inferrence algorighm seems to
> have a problem. Let's consider the following function:
>
> function f(it: Iterator<Xml>): List<String> {
> var list: List<String> = new List<String>();
>
> if (it.hasNext()) {
> Lambda.fold(it.next().elementsNamed("element"),
> function (s, l) { l.add(s.iterator().next().nodeValue); return l; }, list);
> }
>
> return list;
> }
>
> This does not compile with haxe 1.04 returning a bunch of typing
> errors in the anonymous function declared inside Lambda.fold().
> However, if I type this function explicitly:
> function (s: Xml, l: List<String>) ( /* same code here */ }
>
> the fragment compiles perfectly. I believe that type inferrence
> should work better for this example...
If you read carefully the error message, you will see that it prints
"Inconsistent getter for field nodeValue".
That will give you an tip on what's going wrong : since you access the
s.iterator whitout knowing its type, it deduces since this is an
iterator over objets having a "normal field" nodeValue, while
Xml.nodeValue has a getter/setter.
Hence the error, which is quite lengthy I agree, since it's quite deep
in the unification phase.
Nicolas
More information about the Haxe
mailing list