higher-order.ts 582 B

12345678910111213141516
  1. // Higher-order dispatch: `f` is dynamically one of two functions. The call resolves
  2. // through the tracked function-value set; a non-singleton set widens (clears
  3. // exactness). Expected: source -> ask#1 exact, ask#1 -> ask#2 INEXACT (widened by
  4. // the higher-order call), ask#2 -> sink exact.
  5. function g(x: string): string {
  6. return x;
  7. }
  8. function h(x: string): string {
  9. return `H:${x}`;
  10. }
  11. const seed = await agent("seed").ask<string>("seed");
  12. const f = seed.length > 3 ? g : h;
  13. const routed = f(seed);
  14. const out = await agent("out").ask<string>(`route ${routed}`);
  15. return out;