Skip to content

Commit 6b22c2e

Browse files
authored
Merge pull request #120 from haskellari/prepare-2.1
Fix comparable of PartialOrd (a,b) instance, remove Stacked in favour of Either
2 parents 228fd3a + 8d80a90 commit 6b22c2e

File tree

6 files changed

+50
-116
lines changed

6 files changed

+50
-116
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.1 (2022-12-27)
2+
3+
- Fix `comprable` for `PartialOrd (a,b)` instance
4+
- Remove `Stacked`, use `Either` instead for ordinal sum.
5+
There is no type for disjoint union / parallel composition.
6+
Open an issue if you need one.
7+
Terminology is from https://en.wikipedia.org/wiki/Partially_ordered_set#Sums_of_partially_ordered_sets
8+
19
# 2.0.3 (2021-10-30)
210

311
- Add instances for `Solo`

lattices.cabal

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cabal-version: 1.18
22
name: lattices
3-
version: 2.0.3
4-
x-revision: 4
3+
version: 2.1
54
category: Math
65
license: BSD3
76
license-file: LICENSE
@@ -69,7 +68,6 @@ library
6968
Algebra.Lattice.N5
7069
Algebra.Lattice.Op
7170
Algebra.Lattice.Ordered
72-
Algebra.Lattice.Stacked
7371
Algebra.Lattice.Unicode
7472
Algebra.Lattice.Wide
7573
Algebra.Lattice.ZeroHalfOne

src/Algebra/Lattice.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,32 @@ instance (BoundedJoinSemiLattice a, BoundedJoinSemiLattice b) => BoundedJoinSemi
310310
instance (BoundedMeetSemiLattice a, BoundedMeetSemiLattice b) => BoundedMeetSemiLattice (a, b) where
311311
top = (top, top)
312312

313+
--
314+
-- Either
315+
--
316+
317+
-- | Ordinal sum.
318+
--
319+
-- @since 2.1
320+
instance (Lattice a, Lattice b) => Lattice (Either a b) where
321+
Right x \/ Right y = Right (x \/ y)
322+
u@(Right _) \/ _ = u
323+
_ \/ u@(Right _) = u
324+
Left x \/ Left y = Left (x \/ y)
325+
326+
Left x /\ Left y = Left (x /\ y)
327+
l@(Left _) /\ _ = l
328+
_ /\ l@(Left _) = l
329+
Right x /\ Right y = Right (x /\ y)
330+
331+
-- | @since 2.1
332+
instance (BoundedJoinSemiLattice a, Lattice b) => BoundedJoinSemiLattice (Either a b) where
333+
bottom = Left bottom
334+
335+
-- | @since 2.1
336+
instance (Lattice a, BoundedMeetSemiLattice b) => BoundedMeetSemiLattice (Either a b) where
337+
top = Right top
338+
313339
--
314340
-- Bools
315341
--

src/Algebra/Lattice/Stacked.hs

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/Algebra/PartialOrd.hs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,19 @@ instance (PartialOrd a, PartialOrd b) => PartialOrd (a, b) where
148148
-- ordering is incompatible with the transitivity axiom we require for the derived partial order
149149
(x1, y1) `leq` (x2, y2) = x1 `leq` x2 && y1 `leq` y2
150150

151-
comparable (x1, y1) (x2, y2) = comparable x1 x2 && comparable y1 y2
152-
153-
-- | @since 2.0.1
151+
-- | Ordinal sum.
152+
--
153+
-- @since 2.1
154154
instance (PartialOrd a, PartialOrd b) => PartialOrd (Either a b) where
155-
Left x `leq` Left y = leq x y
156-
Right x `leq` Right y = leq x y
157-
leq _ _ = False
155+
leq (Right x) (Right y) = leq x y
156+
leq (Right _) _ = False
157+
leq _ (Right _) = True
158+
leq (Left x) (Left y) = leq x y
158159

159-
comparable (Left x) (Left y) = comparable x y
160160
comparable (Right x) (Right y) = comparable x y
161-
comparable _ _ = False
161+
comparable (Right _) _ = True
162+
comparable _ (Right _) = True
163+
comparable (Left x) (Left y) = comparable x y
162164

163165
-- | Least point of a partially ordered monotone function. Checks that the function is monotone.
164166
lfpFrom :: PartialOrd a => a -> (a -> a) -> a

test/Tests.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ import qualified Algebra.Lattice.Lexicographic as LO
4444
import qualified Algebra.Lattice.Lifted as U
4545
import qualified Algebra.Lattice.Op as Op
4646
import qualified Algebra.Lattice.Ordered as O
47-
import qualified Algebra.Lattice.Stacked as S
4847
import qualified Algebra.Lattice.Wide as W
4948

5049
import Data.HashMap.Lazy (HashMap)
@@ -90,11 +89,14 @@ tests = testGroup "Tests"
9089
, allLatticeLaws (LBounded Partial Modular) (Proxy :: Proxy (W.Wide Int))
9190
, allLatticeLaws (LBounded Partial NonModular) (Proxy :: Proxy (LO.Lexicographic (Set Bool) (Set Bool)))
9291
, allLatticeLaws (LBounded Partial NonModular) (Proxy :: Proxy (LO.Lexicographic M2 M2)) -- non distributive!
93-
, allLatticeLaws (LBounded Partial Distributive) (Proxy :: Proxy (S.Stacked M2 M2))
94-
, allLatticeLaws (LBounded Partial NonModular) (Proxy :: Proxy (S.Stacked M3 N5)) -- non modular, though it takes QC time to find
92+
9593

9694
, allLatticeLaws LNotLattice (Proxy :: Proxy String)
9795

96+
, allLatticeLaws (LBounded Partial Modular) (Proxy :: Proxy (M2, M2))
97+
, allLatticeLaws (LBounded Partial Distributive) (Proxy :: Proxy (Either M2 M2))
98+
, allLatticeLaws (LBounded Partial NonModular) (Proxy :: Proxy (Either M3 N5)) -- non modular, though it takes QC time to find
99+
98100
, allLatticeLaws (LHeyting Total IsBoolean) (Proxy :: Proxy All)
99101
, allLatticeLaws (LHeyting Total IsBoolean) (Proxy :: Proxy Any)
100102
, allLatticeLaws (LHeyting Partial IsBoolean) (Proxy :: Proxy (Endo Bool)) -- note: it's partial!
@@ -122,7 +124,6 @@ tests = testGroup "Tests"
122124
, monadLaws "Op" (Proxy1 :: Proxy1 Op.Op)
123125
, monadLaws "Ordered" (Proxy1 :: Proxy1 O.Ordered)
124126
, monadLaws "Wide" (Proxy1 :: Proxy1 W.Wide)
125-
, monadLaws "Stacked" (Proxy1 :: Proxy1 (S.Stacked N5))
126127
, monadLaws "Heyting.Free" (Proxy1 :: Proxy1 HF.Free)
127128

128129
, finiteLaws (Proxy :: Proxy M2)
@@ -137,7 +138,6 @@ tests = testGroup "Tests"
137138
, finiteLaws (Proxy :: Proxy (L.Levitated OInt8))
138139
, finiteLaws (Proxy :: Proxy (U.Lifted OInt8))
139140
, finiteLaws (Proxy :: Proxy (LO.Lexicographic OInt8 OInt8))
140-
, finiteLaws (Proxy :: Proxy (S.Stacked OInt8 OInt8))
141141
]
142142

143143
type OInt8 = O.Ordered Int8

0 commit comments

Comments
 (0)