Skip to content

Commit 048ce2e

Browse files
committed
Implement algebra#108
1 parent 7ff1809 commit 048ce2e

File tree

4 files changed

+5
-37
lines changed

4 files changed

+5
-37
lines changed

algebra-core/src/main/scala/cats/algebra/lattice/Bool.scala

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ trait Bool[@sp(Int, Long) A] extends Any with Heyting[A] with GenBool[A] { self
3434
or(without(a, b), without(b, a))
3535

3636
override def dual: Bool[A] = new DualBool(this)
37-
38-
/**
39-
* Every Boolean algebra is a BoolRing, with multiplication defined as
40-
* `and` and addition defined as `xor`. Bool does not extend BoolRing
41-
* because, e.g. we might want a Bool[Int] and CommutativeRing[Int] to
42-
* refer to different structures, by default.
43-
*
44-
* Note that the ring returned by this method is not an extension of
45-
* the `Rig` returned from `BoundedDistributiveLattice.asCommutativeRig`.
46-
*/
47-
override def asBoolRing: BoolRing[A] = new BoolRingFromBool(self)
4837
}
4938

5039
class DualBool[@sp(Int, Long) A](orig: Bool[A]) extends Bool[A] {
@@ -63,7 +52,7 @@ class DualBool[@sp(Int, Long) A](orig: Bool[A]) extends Bool[A] {
6352
override def dual: Bool[A] = orig
6453
}
6554

66-
private[lattice] class BoolRingFromBool[A](orig: Bool[A]) extends BoolRngFromGenBool(orig) with BoolRing[A] {
55+
class BoolRingFromBool[A](orig: Bool[A]) extends BoolRngFromGenBool(orig) with BoolRing[A] {
6756
def one: A = orig.one
6857
}
6958

@@ -79,7 +68,6 @@ class BoolFromBoolRing[A](orig: BoolRing[A]) extends GenBoolFromBoolRng(orig) wi
7968
def one: A = orig.one
8069
def complement(a: A): A = orig.plus(orig.one, a)
8170
override def without(a: A, b: A): A = super[GenBoolFromBoolRng].without(a, b)
82-
override def asBoolRing: BoolRing[A] = orig
8371

8472
override def meet(a: A, b: A): A = super[GenBoolFromBoolRng].meet(a, b)
8573
override def join(a: A, b: A): A = super[GenBoolFromBoolRng].join(a, b)

algebra-core/src/main/scala/cats/algebra/lattice/BoundedDistributiveLattice.scala

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package algebra
33
package lattice
44

55
import scala.{specialized => sp}
6-
import cats.algebra.ring.CommutativeRig
76

87
/**
98
* A bounded distributive lattice is a lattice that both bounded and distributive
@@ -13,18 +12,6 @@ trait BoundedDistributiveLattice[@sp(Int, Long, Float, Double) A]
1312
with BoundedLattice[A]
1413
with DistributiveLattice[A] { self =>
1514

16-
/**
17-
* Return a CommutativeRig using join and meet. Note this must obey the commutative rig laws since
18-
* meet(a, one) = a, and meet and join are associative, commutative and distributive.
19-
*/
20-
def asCommutativeRig: CommutativeRig[A] =
21-
new CommutativeRig[A] {
22-
def zero: A = self.zero
23-
def one: A = self.one
24-
def plus(x: A, y: A): A = self.join(x, y)
25-
def times(x: A, y: A): A = self.meet(x, y)
26-
}
27-
2815
override def dual: BoundedDistributiveLattice[A] = new BoundedDistributiveLattice[A] {
2916
def meet(a: A, b: A) = self.join(a, b)
3017
def join(a: A, b: A) = self.meet(a, b)

algebra-core/src/main/scala/cats/algebra/lattice/GenBool.scala

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ trait GenBool[@sp(Int, Long) A] extends Any with DistributiveLattice[A] with Bou
3030
* Defined as `a\b ∨ b\a`.
3131
*/
3232
def xor(a: A, b: A): A = or(without(a, b), without(b, a))
33-
34-
/**
35-
* Every generalized Boolean algebra is also a `BoolRng`, with
36-
* multiplication defined as `and` and addition defined as `xor`.
37-
*/
38-
def asBoolRing: BoolRng[A] = new BoolRngFromGenBool(self)
3933
}
4034

4135
/**
@@ -48,17 +42,16 @@ trait GenBool[@sp(Int, Long) A] extends Any with DistributiveLattice[A] with Bou
4842
*
4943
* `BoolRng.asBool.asBoolRing` gives back the original `BoolRng`.
5044
*
51-
* @see [[algebra.lattice.GenBool.asBoolRing]]
45+
* @see [[algebra.lattice.BoolRngFromGenBool]]
5246
*/
5347
class GenBoolFromBoolRng[A](orig: BoolRng[A]) extends GenBool[A] {
5448
def zero: A = orig.zero
5549
def and(a: A, b: A): A = orig.times(a, b)
5650
def or(a: A, b: A): A = orig.plus(orig.plus(a, b), orig.times(a, b))
5751
def without(a: A, b: A): A = orig.plus(a, orig.times(a, b))
58-
override def asBoolRing: BoolRng[A] = orig
5952
}
6053

61-
private[lattice] class BoolRngFromGenBool[@sp(Int, Long) A](orig: GenBool[A]) extends BoolRng[A] {
54+
class BoolRngFromGenBool[@sp(Int, Long) A](orig: GenBool[A]) extends BoolRng[A] {
6255
def zero: A = orig.zero
6356
def plus(x: A, y: A): A = orig.xor(x, y)
6457
def times(x: A, y: A): A = orig.and(x, y)

algebra-laws/shared/src/test/scala/cats/algebra/laws/LawTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class LawTests extends munit.DisciplineSuite {
5959
checkAll("Boolean", RingLaws[Boolean].boolRing(booleanRing))
6060

6161
// ensure that Bool[A].asBoolRing is a valid BoolRing
62-
checkAll("Boolean-ring-from-bool", RingLaws[Boolean].boolRing(Bool[Boolean].asBoolRing))
62+
checkAll("Boolean-ring-from-bool", RingLaws[Boolean].boolRing(new BoolRingFromBool[Boolean](Bool[Boolean])))
6363

6464
// ensure that BoolRing[A].asBool is a valid Bool
6565
checkAll("Boolean- bool-from-ring", LogicLaws[Boolean].bool(new BoolFromBoolRing(booleanRing)))
@@ -90,7 +90,7 @@ class LawTests extends munit.DisciplineSuite {
9090
checkAll("Set[Byte]", LogicLaws[Set[Byte]].generalizedBool)
9191
checkAll("Set[Byte]", RingLaws[Set[Byte]].boolRng(setBoolRng[Byte]))
9292
checkAll("Set[Byte]-bool-from-rng", LogicLaws[Set[Byte]].generalizedBool(new GenBoolFromBoolRng(setBoolRng)))
93-
checkAll("Set[Byte]-rng-from-bool", RingLaws[Set[Byte]].boolRng(GenBool[Set[Byte]].asBoolRing))
93+
checkAll("Set[Byte]-rng-from-bool", RingLaws[Set[Byte]].boolRng(new BoolRngFromGenBool(GenBool[Set[Byte]])))
9494
checkAll("Set[Int]", PartialOrderTests[Set[Int]].partialOrder)
9595
checkAll("Set[Int]", RingLaws[Set[Int]].semiring)
9696
checkAll("Set[String]", RingLaws[Set[String]].semiring)

0 commit comments

Comments
 (0)