-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Some MonadRec instances. #1041
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
Some MonadRec instances. #1041
Conversation
69355d6 to
85eabda
Compare
Current coverage is 87.88%
@@ master #1041 diff @@
==========================================
Files 215 217 +2
Lines 2744 2755 +11
Methods 2690 2690
Messages 0 0
Branches 49 60 +11
==========================================
- Hits 2424 2421 -3
- Misses 320 334 +14
Partials 0 0
|
85eabda to
909a427
Compare
|
|
||
| class MonadRecInstancesTests extends CatsSuite { | ||
| def tailRecMStackSafety[M[_]](implicit M: MonadRec[M], Eq: Eq[M[Int]]): Unit = { | ||
| val n = 50000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this test be added as a MonadRecLaws and MonadRecTests in the cats-laws project, with tests for instances being put in OptionTests, XorTests, etc. ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A law that tailRecM is consistent with flatMap would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adelbertc Is it OK to call that unit test a law?
@ceedubs The best I can think of is testing that tailRecM is consistent with the naive (non-stack safe) implementation of tailRecM that uses recursive flatMaps (and is implemented uniformly for any monad):
def naiveTailRecM[M[_], A, B](a: A)(f: A => M[A Xor B])(implicit M: Monad[M]): M[B] =
M.flatMap(f(a))(_ match {
case Xor.Left(a1) => naiveTailRecM(a1)(f)
case Xor.Right(b) => M.pure(b)
})(This is also basically the implementation of tailRecM for Free, where it is OK, because Free is lazy.)
Did you have something else in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasMikula I was thinking of something like what scalaz has.
Regarding @adelbertc's comment, I have a little hesitation adding something like that as a law. Mostly because it could potentially take a really long time to run for some types. I'm not writing it off as a possibility, just raising a potential concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ceedubs laws added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomasMikula nice! Thank you for this. I'll do a more detailed review shortly.
|
@mpilquist ScalaDoc generation fails on this line in scala 2.10 but succeeds if I remove the |
|
Thanks @TomasMikula! This looks like a good start to me. |
909a427 to
2617222
Compare
|
Unsure why it's failing but 👍 once we figure that out |
|
The build failure seems to be the same as #898 (comment) |
|
@adelbertc Do you want to review #1051 which should unblock this one? |
|
@TomasMikula #1051 has been merged. Sorry, but would you be willing to rebase? |
2617222 to
4f54045
Compare
|
Great! 👍 when Travis is green. |
4f54045 to
5a38209
Compare
Some
MonadRecinstances to get started. This is a follow-up on #1040.