haxetink / tink_streams

Streams from the future. With lasers, of course ... whoaaaaa!!!!
The Unlicense
12 stars 9 forks source link

Type inference in forEach (and probably others) #16

Closed kevinresol closed 6 years ago

kevinresol commented 7 years ago

So this code:

stream.forEach(function(data) {
  $type(data);
  return Resume;
});

gives Unknown<0>

Any idea how to make it correctly infer the type?

back2dos commented 7 years ago

I just played around a little and I think https://github.com/haxetink/tink_streams/commit/5262af1c6a06c3b09d5817e93a0aeb85a39cc7d7 might improve it quite a bit. Can you confirm?

kevinresol commented 6 years ago

This seems worked. I wonder what magic has been done.

back2dos commented 6 years ago

It's basically this again: https://github.com/haxetink/tink_core/issues/59

To be able to write return Resume;, I had wrapped the function in { apply: ... }, so that the compiler must infer the function bottom up and then uses the implicit cast. But because of that, the argument type becomes unknown.