Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply tail-call rec to List.FlattenN + write stress tests #50

Open
poteat opened this issue Aug 8, 2023 · 0 comments
Open

Apply tail-call rec to List.FlattenN + write stress tests #50

poteat opened this issue Aug 8, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@poteat
Copy link
Owner

poteat commented Aug 8, 2023

In the following code:

type _$flattenN2<
  T extends unknown[],
  N extends DigitList.DigitList,
  N_NEXT extends DigitList.DigitList = DigitList._$decrement<N>,
  RESULT extends List.List = N extends [Digit.Zero]
    ? T
    : _$flattenN2<_$flattenShallow<T>, N_NEXT>
> = RESULT

type _$flattenShallow<
  T extends unknown[],
  RESULT extends List.List = T extends [infer H, ...infer R]
    ? H extends unknown[]
      ? [...H, ..._$flattenShallow<R>]
      : [H, ..._$flattenShallow<R>]
    : []
> = RESULT

The following clauses violate rules around tail-call rec optimization:

  • [...H, ..._$flattenShallow<R>]
  • [H, ..._$flattenShallow<R>]

I think this can be written to be more performant thereby - as well, adding stress tests would validate this.

@MajorLift MajorLift added enhancement New feature or request research and removed research labels Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants