How to avoid stack overflow when using scalaz's free monad?

拜拜、爱过 提交于 2019-12-04 03:36:28

The Id monad is not trampolined. You end up in an infinite mutual recursion between the bind method for the Id monad and the foldMap method for the free monad. Use Trampoline or Task instead of Id.

Since @Apocalisp's answer, there has been addition of BindRec typeclass and foldMapRec method that can be used for stack-safe evaluation directly to Id (or any other "tail-recursive" monad). For details, read Stack Safety for Free.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!