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

Make schemes stack-safe using Eval #7

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

DavidGregory084
Copy link
Owner

Makes the schemes in this project stack safe using the awesome idea from this gist by @Baccata.

Things I still need to do:

  • Add stack-safety tests for some of the schemes
  • Try to unpick the tangled logic of some of the more obscure schemes (e.g. histo)

Questions I still have:

  • How much slower is it?!?!! 😛
  • How much of a problem is it in practice to have the more restrictive Traverse constraint
  • Can I rewrite the monadic schemes to use tailRecM?
  • What are the laws for prepro and postpro? I have fiddled with the implementations and want to make sure the transformations happen in the right place - I can probably look in one of the other recursion schemes libraries for this
  • Is it more efficient to add stack-safety using the approach described here, using a type class which decomposes the data structure rather than relying on Eval to make traverse stack-safe?

@Baccata
Copy link

Baccata commented Jul 3, 2020

@DavidGregory084, ha, I had completely forgotten about this. After many thoughts, I think I had come to the realisation that the use of Eval there was just a specific use of hyloM, and had elected to use the generic hyloM(which requires a Traverse anyway) combined with whatever stack safe monad was best suited to the code I was writing (which may or may not have been Eval)

How much of a problem is it in practice to have the more restrictive Traverse constraint

Theoretically, I think it becomes a problem if your pattern functor has lazy/by-name components to it. I don't think this is a very common case but a library should tread lightly with this kind of decision.

Can I rewrite the monadic schemes to use tailRecM

I don't think it's possible to achieve generically, as the pattern-functor is the structure that "knows" when recursion stops and when to start producing Bs. Without intricate runtime typechecks, it's likely impossible.

@DavidGregory084
Copy link
Owner Author

Yeah, that totally makes sense, I considered removing the non-monadic schemes from the library. I can see how it wouldn't be possible to use tailRecM due to the type class instances handling all of the recursion. I think I might have to go down the rabbit hole of the "Dissectible" type class. 😆

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.

2 participants