Skip to content

Commit c49979d

Browse files
committedMar 23, 2025··
add ordinal direction documentation to sum lattice
1 parent 0c173c1 commit c49979d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed
 

‎Modules/RDTs/src/main/scala/rdts/base/Lattice.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ trait Lattice[A] {
3333
/** Merging `right` into `left` has no effect */
3434
inline def subsumes(right: A): Boolean = Lattice.this.subsumption(right, left)
3535

36-
/** Merging `left` and `right` would be strictly larger than right */
3736
inline def inflates(right: A): Boolean = !Lattice.this.subsumption(left, right)
3837

3938
@targetName("mergeInfix")
@@ -148,11 +147,16 @@ object Lattice {
148147
*/
149148
inline given tupleLattice[T <: Tuple](using pm: Mirror.ProductOf[T]): Lattice[T] = derived
150149

150+
inline def derived[T <: Product : Mirror.ProductOf]: Lattice[T] = productLattice
151+
152+
/** Sum Lattice merges considers later defined (those with larger ordinals) constructors as larger.
153+
* Notably, this implies `None < Some` for Option and `Left < Right` for Either.
154+
* For an `enum E { case A, B, C }` it will be `A < B < C` */
151155
inline def sumLattice[T](using sm: Mirror.SumOf[T]): Lattice[T] =
152156
val lattices: Tuple = summonAll[Tuple.Map[sm.MirroredElemTypes, Lattice]]
153157
new Derivation.SumLattice[T](sm, lattices)
154158

155-
inline def derived[T <: Product](using pm: Mirror.ProductOf[T]): Lattice[T] = {
159+
inline def productLattice[T <: Product](using pm: Mirror.ProductOf[T]): Lattice[T] = {
156160
val lattices: Tuple = summonAll[Tuple.Map[pm.MirroredElemTypes, Lattice]]
157161
val bottoms: Tuple = Derivation.summonAllMaybe[Tuple.Map[pm.MirroredElemTypes, Bottom]]
158162
new Derivation.ProductLattice[T](lattices, bottoms, pm, valueOf[pm.MirroredLabel])

0 commit comments

Comments
 (0)
Please sign in to comment.