Skip to content

Conversation

@rhendric
Copy link
Member

@rhendric rhendric commented May 7, 2022

tailRec2 and tailRec3 complete the tailRec and tailRecM matrix,
and loop2 and loop3 are new conveniences for both tailRec2/3 and
tailRecM2/3 that better abstract the consumer away from the details of
the a, b, c record labels we use in those functions.

Description of the change

Submitting this for discussion in preparation for doing something about purescript/purescript#4289. All of these new functions are optional for that proposal, but before we go hard on promoting purescript-tailrec as the best way to ensure that one's stack-hungry functions execute safely, I think we should address these rough edges, and standardizing on them will make it possible to optimize them out.


Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

go (Loop a) = go (f a)
go (Done b) = b

-- | Create a pure tail-recursive function of two arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add docs that refer to loop2 here? Otherwise, it's not immediately clear that one would know to use loop2 in tandem with tailRec2

tailRec2 :: forall a b c. (a -> b -> Step { a :: a, b :: b } c) -> a -> b -> c
tailRec2 f a b = tailRec (\o -> f o.a o.b) { a, b }

-- | Create a pure tail-recursive function of three arguments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here for loop3?

`tailRec2` and `tailRec3` complete the `tailRec` and `tailRecM` matrix,
and `loop2` and `loop3` are new conveniences for both `tailRec2/3` and
`tailRecM2/3` that better abstract the consumer away from the details of
the `a`, `b`, `c` record labels we use in those functions.
@rhendric rhendric force-pushed the rhendric/tailRec2-etc branch from 39c7ba6 to 5ac167d Compare May 17, 2022 00:37
Copy link
Contributor

@JordanMartinez JordanMartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@JordanMartinez JordanMartinez merged commit 81ac782 into purescript:master May 17, 2022
@JordanMartinez
Copy link
Contributor

This was released in v6.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants