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

Arrow Typeclass #282

Open
austindd opened this issue Nov 20, 2020 · 0 comments
Open

Arrow Typeclass #282

austindd opened this issue Nov 20, 2020 · 0 comments

Comments

@austindd
Copy link
Contributor

I have been working on implementing a stack-safe Arrow typeclass, and my current implementation is stack-safe both for function-composition and for evaluation. It's still a work in progress, but you can view it here:

https://github.com/austindd/reason-arrow

The underlying representation is a GADT binary tree of "composed" functions. This replaces the need for nested closures to represent lazy function composition. Therefore, constructing an Arrow type avoids stack overflow.

Arrow evaluation is also fully tail-recursive. It does this by maintaining its own well-typed stack of continuations (the right-hand side of the binary tree). This allows us to fully evaluate composed Arrow types without blowing the stack.

This abstraction might be useful elsewhere. For example, I have an example of a Lazy monad implemented in terms of Arrow, with a stack-safe bind operation. You can find that here:

https://github.com/austindd/reason-arrow/blob/main/src/TestLazy.re

Keep in mind that parts of this Arrow typeclass implementation might be flawed. I am going off the Haskell definitions, but don't have much experience with Haskell, so I am certain I've made some mistakes. That said, I'm interested in feedback. If this is a good candidate for inclusion in relude, I would be interested in a more detailed discussion.

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

No branches or pull requests

1 participant