-
Notifications
You must be signed in to change notification settings - Fork 114
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
Define laws for Traversable #442
Conversation
/** | ||
* Traversing by `Id` is equivalent to mapping. | ||
*/ | ||
val identityLaw: LawsF.Covariant[DeriveEqualTraversable, Equal] = { |
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.
You can implement your own law until we add one to ZIO Test.
@@ -269,11 +270,25 @@ trait Traversable[F[+_]] extends Covariant[F] { | |||
|
|||
object Traversable extends LawfulF.Covariant[DeriveEqualTraversable, Equal] { | |||
|
|||
// need to implement natural transformations for this property? | |||
// val naturalityLaw: LawsF.Covariant[DeriveEqualTraversable, Equal] = ??? |
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.
I think we can restate this as a fusion law that if we have F[G[H[A]]]
where F
is traversable and G
and H
have IdentityBoth
and Covariant
then we can individually flip
twice or we can create a composed instance and flip
the whole thing once.
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.
Thanks for the big tip!
@adamgfraser can you check if I'm going in the right direction so far? AFAICT, there's still lots of work to be done, like making it so the |
a0b4272
to
fc8bf61
Compare
- make newtypes for `Nested` functors and functor `Product`s - make instances needed for everything to work - add type ascriptions to make compiler happy in Traversable.scala
* | ||
* If F[_] and G[_] are both IdentityBoth, then Nested[F, G, *] is also an IdentityBoth. | ||
* | ||
* If F[_] and G[_] are both Traversable, then Nested[F, G, *] is also a Traversable. |
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.
I think it would be nice to add tests for that at CovariantSpec, IdentityBothSpec, TraversableSpec
can copy it from my branch:
Badmoonz@6df1301#diff-82e9bed52abfcc1cabd8fb86c811dcab611fbd08d2ff81124a90af2fb0a78834R21
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.
So I tried to add the ones for CovariantSpec
& IdentityBothSpec
, and they led to the same build errors for 2.11 in #449. Any idea on how to make them work?
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.
After some research , I've found solution : make alias type for nested
{
type T[+A] = Nested[Vector, Option]
testM("Nested[vector,option]")(checkAllLaws(Traversable)(GenFs.nested(GenF.vector, GenF.option) : GenF[T, Random with Sized] , Gen.anyInt))
}
It looks like scala 2.11 compiler cannot derive type CapF[_[_[_]]]
from first argument GenFs.nested(GenF.vector, GenF.option) which has type GenF[(lambda[+A] = Nested[Vector, Option, A)#lambda, Random with Sized]
.
I supposed that's because it has lambda type param, but CovariantSpec has tuple, either gens that also return GenF with lambda type param, and it works well
7de4d81
to
9150898
Compare
282d2ee
to
c660070
Compare
@adamgfraser @zalbia @sideeffffect This one ready to merge (aside from merge conflicts)??? |
# Conflicts: # core/shared/src/test/scala/zio/prelude/TraversableSpec.scala
@jdegoes it may turn out we may need just one law for Traversable #373 (comment) |
We should merge #449 once the PR passes checks. |
@zalbia 👍 |
ok, i will update und fix #449 today |
closes #373