-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
StackOverflowError on traverse[Kleisli[F, A, ?], B] #2212
Comments
@alexandru recently did some nice stack-safety work for |
Overriding override def map2[B, C, D](fb: Kleisli[F, A, B], fc: Kleisli[F, A, C])(f: (B, C) => D): Kleisli[F, A, D] =
Kleisli(a => F.flatMap(F.pure(()))(_ => F.map2(fb.run(a), fc.run(a))(f))) Maybe we can come up with something better though ...? The easiest solution at the moment (I think) is to lift to List.fill(100000)(1).traverse[Free[Kleisli[F, Int, ?], ?], Int](a =>
Free.liftF(Kleisli.pure(a))
).runTailRec.run(1) |
The This solution defers the stack safety to I lean towards doing the same trick for When is that scheduled btw? |
This feels a little off to me, like we are smuggling a suspend into Monad. I mean, we could have a function like that with the only law that it is the same as identity, but it feels like code smell. I hate to copy that pure/flatMap snippet around though because we somehow feel that is okay but naming it is not. Maybe unsafeSuspend? I would prefer a more direct assault on Traverse stack safety. If we could find an analog of tailRecM for applicatives we would be in business. |
You mean we need a name for That said Kleisli's current encoding is
I couldn't find a way for the Note that |
The following snippet throws a StackOverflowError (assuming kind-projector plugin):
The equivalent snippet without Kleisli (
List.fill(100000)(1).traverse[F, Int](a => Applicative[F].pure(a))
) runs as expected.Top of the stacktrace:
The text was updated successfully, but these errors were encountered: