Skip to content
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

Fixes #2631 Fix InvariantMonoidal Laws #2711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions laws/src/main/scala/cats/laws/InvariantMonoidalLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ trait InvariantMonoidalLaws[F[_]] extends InvariantSemigroupalLaws[F] {
def invariantMonoidalRightIdentity[A, B](fa: F[A]): IsEq[F[A]] =
fa.product(F.unit).imap(_._1)(a => (a, ())) <-> fa

def invariantMonoidalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): IsEq[F[(A, (B, C))]] =
fa.product(fb.product(fc)) <-> fa
.product(fb)
.product(fc)
.imap { case ((a, b), c) => (a, (b, c)) } { case (a, (b, c)) => ((a, b), c) }
}

object InvariantMonoidalLaws {
Expand Down
8 changes: 8 additions & 0 deletions laws/src/main/scala/cats/laws/InvariantSemigroupalLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ package laws
*/
trait InvariantSemigroupalLaws[F[_]] extends InvariantLaws[F] with SemigroupalLaws[F] {
implicit override def F: InvariantSemigroupal[F]
import cats.syntax.semigroupal._
import cats.syntax.invariant._

def invariantSemigroupalAssociativity[A, B, C](fa: F[A], fb: F[B], fc: F[C]): IsEq[F[(A, (B, C))]] =
fa.product(fb.product(fc)) <-> fa
.product(fb)
.product(fc)
.imap { case ((a, b), c) => (a, (b, c)) } { case (a, (b, c)) => ((a, b), c) }
}

object InvariantSemigroupalLaws {
def apply[F[_]](implicit ev: InvariantSemigroupal[F]): InvariantSemigroupalLaws[F] =
new InvariantSemigroupalLaws[F] { def F: InvariantSemigroupal[F] = ev }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ trait InvariantMonoidalTests[F[_]] extends InvariantSemigroupalTests[F] {
EqFABC2: Eq[F[(A, B, C)]],
iso: Isomorphisms[F],
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]]): RuleSet =
new RuleSet {
val name = "invariantMonoidal"
val parents = Seq(invariant[A, B, C], semigroupal[A, B, C])
val parents = Seq(invariantSemigroupal[A, B, C])
val bases = Seq.empty
val props = Seq(
"invariant monoidal left identity" -> forAll((fa: F[A]) => laws.invariantMonoidalLeftIdentity(fa)),
"invariant monoidal right identity" -> forAll((fa: F[A]) => laws.invariantMonoidalRightIdentity(fa)),
"invariant monoidal associativity" -> forAll(
(fa: F[A], fb: F[B], fc: F[C]) => laws.invariantMonoidalAssociativity(fa, fb, fc)
)
"invariant monoidal right identity" -> forAll((fa: F[A]) => laws.invariantMonoidalRightIdentity(fa))
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package cats
package laws
package discipline

import cats.InvariantSemigroupal
import cats.laws.discipline.SemigroupalTests.Isomorphisms
import org.scalacheck.Prop.forAll
import org.scalacheck.{Arbitrary, Cogen}

trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with SemigroupalTests[F] {
Expand All @@ -19,12 +19,17 @@ trait InvariantSemigroupalTests[F[_]] extends InvariantTests[F] with Semigroupal
EqFA: Eq[F[A]],
EqFB: Eq[F[B]],
EqFC: Eq[F[C]],
EqFABC: Eq[F[(A, B, C)]],
EqFABC: Eq[F[(A, (B, C))]],
EqFABC2: Eq[F[(A, B, C)]],
iso: Isomorphisms[F]): RuleSet = new RuleSet {
val name = "invariantSemigroupal"
val parents = Seq(invariant[A, B, C], semigroupal[A, B, C])
val bases = Nil
val props = Nil
val props = Seq(
"invariant semigroupal associativity" -> forAll(
(fa: F[A], fb: F[B], fc: F[C]) => laws.invariantSemigroupalAssociativity(fa, fb, fc)
)
)
}
}

Expand Down