Closed adelbertc closed 8 years ago
@adelbertc Is this resolved? I noticed that you closed the issue but it seems like we might potentially still have some surprises here (such as your reduceLeft + map2 example).
@ceedubs I closed it because I thought it was one of those "that's just the way it is" situations. But if you think this is a bug then let's go ahead and open up the books again
Playing with some finally tagless as one would expect of me. Some surprising behavior, not sure if intended. Here's the Scalaz version, which works fine, doesn't blow stack (scroll to the bottom of the snippet to
ScalazApp
to get to the point):Here's the Cats equivalent I think (only things changed are Cats Monad definitions and using
Eval
instead ofTrampoline
).This blows stack. The point of interest in the Cats version appears to be:
Recalling @ceedubs 's
map2Eval
addition, I turned it into:which works! So I thought OK maybe it's just
map2
, so let's change it intoflatMap
:Back to blowing stack. Related tweet stream: https://twitter.com/adelbertchang/status/764499222020263936
EDIT OK I tried the for-comprehension equivalent in Scalaz and that also blows stack as well. I think the earlier Scalaz example works because
ap
in Scalaz in by-name: https://github.com/scalaz/scalaz/blob/series/7.3.x/core/src/main/scala/scalaz/Apply.scala#L21 and in Cats it's by-value, but we work around that withmap2Eval
?EDIT2 OK what in the world, in Scalaz
foldLeft1
with for-comp blows stack,foldRight
does not. Probably becausefoldRight
is lazy in Scalaz and in Cats we useEval
: https://github.com/scalaz/scalaz/blob/series/7.3.x/core/src/main/scala/scalaz/Foldable1.scala#L38EDIT3 OK so:
Cats
Scalaz