function.sent beta equivalence?

Bergi a.d.bergi at
Thu Jun 25 12:39:33 UTC 2015

Mark S. Miller schrieb:

> Something strange and bizarre that Jafar and I just discovered after the
> TC39 meeting:
> We all know that there are a set of conventional combinators, like
> flatMap, that work fine for iterators.
> Iterators are uni-directional. Generators are bi-directional. (As Jara
> observes: Generator implements Iterator, Observer)
> We thought that these combinators did not apply to generators in their
> full bidirectional glory. We were wrong.
> Flatmap of generators can approximately be modeled in terms of "yield*
> wrap"

So you have a signature of `Iterable<Generator<i, o, r>> -> Generator<i, 
o, r>` in mind, not a monadic `join`-like function that takes a generator?

> flatMap([g1, g2]) is equivalent to
> (function*() {
>    yield* wrap(g1, function.sent); // result of g1 ignored!
>    return yield* g2;
> }())

Maybe it should be

(function*() {
    return [yield* wrap(g1, function.sent), yield* g2];

with `Iterable<Generator<i, o, r>> -> Generator<i, o, Iterable<r>>`?


More information about the es-discuss mailing list