moonlight-algebra 0.1.0.2 → 0.1.1.0
raw patch · 4 files changed
+141/−84 lines, 4 filesdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: base
API changes (from Hackage documentation)
- Moonlight.Algebra: (<=>) :: HeytingAlgebra a => a -> a -> a
- Moonlight.Algebra: (<>) :: Semigroup a => a -> a -> a
- Moonlight.Algebra: Additive :: a -> Additive a
- Moonlight.Algebra: Batch :: [a] -> Batch a
- Moonlight.Algebra: ChainOrder :: a -> ChainOrder a
- Moonlight.Algebra: FixpointDivergence :: Natural -> a -> FixpointDivergence a
- Moonlight.Algebra: Join :: a -> Join a
- Moonlight.Algebra: Lukasiewicz :: a -> Lukasiewicz a
- Moonlight.Algebra: Meet :: a -> Meet a
- Moonlight.Algebra: Multiplicative :: a -> Multiplicative a
- Moonlight.Algebra: Negative :: Orientation
- Moonlight.Algebra: Positive :: Orientation
- Moonlight.Algebra: SparseLinearMapEntryCountOverflow :: Integer -> SparseLinearMapCompileError
- Moonlight.Algebra: SparseLinearMapNegativeSourceCount :: Int -> SparseLinearMapCompileError
- Moonlight.Algebra: SparseLinearMapOffsetCountOverflow :: Integer -> SparseLinearMapCompileError
- Moonlight.Algebra: SparseLinearMapSourceOutOfBounds :: Int -> SparseLinearMapError
- Moonlight.Algebra: TropicalFinite :: a -> Tropical a
- Moonlight.Algebra: TropicalInfinity :: Tropical a
- Moonlight.Algebra: Viterbi :: a -> Viterbi a
- Moonlight.Algebra: [fixpointDivergenceBudget] :: FixpointDivergence a -> Natural
- Moonlight.Algebra: [fixpointDivergenceLast] :: FixpointDivergence a -> a
- Moonlight.Algebra: [getAdditive] :: Additive a -> a
- Moonlight.Algebra: [getChainOrder] :: ChainOrder a -> a
- Moonlight.Algebra: [getJoin] :: Join a -> a
- Moonlight.Algebra: [getLukasiewicz] :: Lukasiewicz a -> a
- Moonlight.Algebra: [getMeet] :: Meet a -> a
- Moonlight.Algebra: [getMultiplicative] :: Multiplicative a -> a
- Moonlight.Algebra: [getViterbi] :: Viterbi a -> a
- Moonlight.Algebra: act :: Action m s => m -> s -> s
- Moonlight.Algebra: addQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a -> Quotient modulus a -> Quotient modulus a
- Moonlight.Algebra: applySparseLinearMap :: (Eq r, Ring r) => SparseLinearMap r -> SparseIxVec r -> Either SparseLinearMapError (SparseIxVec r)
- Moonlight.Algebra: bilinearForm :: BilinearSpace scalar vector => vector -> vector -> scalar
- Moonlight.Algebra: bottom :: BoundedJoinSemilattice a => a
- Moonlight.Algebra: canonicalRemainder :: CanonicalEuclideanDomain a => a -> NonZeroDivisor a -> a
- Moonlight.Algebra: class Group group => AbelianGroup group
- Moonlight.Algebra: class Monoid m => Action m s
- Moonlight.Algebra: class VectorSpace scalar vector => BilinearSpace scalar vector
- Moonlight.Algebra: class HeytingAlgebra a => BooleanAlgebra a
- Moonlight.Algebra: class JoinSemilattice a => BoundedJoinSemilattice a
- Moonlight.Algebra: class MeetSemilattice a => BoundedMeetSemilattice a
- Moonlight.Algebra: class EuclideanDomain a => CanonicalEuclideanDomain a
- Moonlight.Algebra: class Quantale a => ChainQuantale a
- Moonlight.Algebra: class Quantale a => CommutativeQuantale a
- Moonlight.Algebra: class Ring a => CommutativeRing a
- Moonlight.Algebra: class Lattice a => DistributiveLattice a
- Moonlight.Algebra: class (GCDDomain a, Ord Degree a) => EuclideanDomain a where {
- Moonlight.Algebra: class Module scalar moduleValue => FreeModule scalar moduleValue where {
- Moonlight.Algebra: class IntegralDomain a => GCDDomain a
- Moonlight.Algebra: class Monoid group => Group group
- Moonlight.Algebra: class HasMagnitude obstruction
- Moonlight.Algebra: class (BoundedLattice a, DistributiveLattice a) => HeytingAlgebra a
- Moonlight.Algebra: class (CommutativeRing a, Eq a) => IntegralDomain a
- Moonlight.Algebra: class Quantale a => IntegralQuantale a
- Moonlight.Algebra: class (Group m, Action m s) => InvertibleAction m s
- Moonlight.Algebra: class JoinSemilattice a
- Moonlight.Algebra: class (JoinSemilattice a, MeetSemilattice a) => Lattice a
- Moonlight.Algebra: class MeetSemilattice a
- Moonlight.Algebra: class (Ring scalar, AdditiveGroup moduleValue) => Module scalar moduleValue
- Moonlight.Algebra: class Semigroup a => Monoid a
- Moonlight.Algebra: class (PartialOrder a, Lattice a) => OrderedLattice a
- Moonlight.Algebra: class BoundedJoinSemilattice a => Quantale a
- Moonlight.Algebra: class CommutativeQuantale a => ResiduatedQuantale a
- Moonlight.Algebra: class Semigroup a
- Moonlight.Algebra: class (AdditiveMonoid a, MultiplicativeMonoid a) => Semiring a
- Moonlight.Algebra: class (Field scalar, Module scalar vector) => VectorSpace scalar vector
- Moonlight.Algebra: coefficient :: FreeModule scalar moduleValue => Basis scalar moduleValue -> moduleValue -> scalar
- Moonlight.Algebra: compileSparseLinearMap :: (Eq r, AdditiveMonoid r) => Int -> (Int -> [(Int, r)]) -> Either SparseLinearMapCompileError (SparseLinearMap r)
- Moonlight.Algebra: complement :: BooleanAlgebra a => a -> a
- Moonlight.Algebra: countElementsWithOrderDividing :: Integer -> [Integer] -> Integer
- Moonlight.Algebra: countExactOrderElements :: Integer -> [Integer] -> Integer
- Moonlight.Algebra: crt :: forall left right a. CanonicalEuclideanDomain a => CanonicalResidue left a -> CanonicalResidue right a -> Maybe (CanonicalResidue (CrtMod left right) a)
- Moonlight.Algebra: data CanonicalResidue modulus a
- Moonlight.Algebra: data CrtMod left right
- Moonlight.Algebra: data EndoPatch key
- Moonlight.Algebra: data FixpointDivergence a
- Moonlight.Algebra: data FreeAbelianGroup g
- Moonlight.Algebra: data LaneVector
- Moonlight.Algebra: data Orientation
- Moonlight.Algebra: data Polynomial r
- Moonlight.Algebra: data PowerSet a
- Moonlight.Algebra: data ProductAlgebra (n :: Nat) a
- Moonlight.Algebra: data Quotient modulus a
- Moonlight.Algebra: data QuotientContext modulus a
- Moonlight.Algebra: data SparseIxVec r
- Moonlight.Algebra: data SparseLinearMap r
- Moonlight.Algebra: data SparseLinearMapCompileError
- Moonlight.Algebra: data SparseLinearMapError
- Moonlight.Algebra: data SparseVec r g
- Moonlight.Algebra: data Tropical a
- Moonlight.Algebra: data Zn (n :: Nat)
- Moonlight.Algebra: degree :: EuclideanDomain a => a -> Degree a
- Moonlight.Algebra: divideWithRemainder :: EuclideanDomain a => a -> NonZeroDivisor a -> (a, a)
- Moonlight.Algebra: divisorsFromPrimePowers :: [(Integer, Int)] -> [Integer]
- Moonlight.Algebra: divisorsOf :: Integer -> [Integer]
- Moonlight.Algebra: endoPatch :: Ord key => Set key -> Set key -> EndoPatch key
- Moonlight.Algebra: endoPatchAdds :: EndoPatch key -> Set key
- Moonlight.Algebra: endoPatchRemoves :: EndoPatch key -> Set key
- Moonlight.Algebra: evaluatePolynomial :: Ring r => r -> Polynomial r -> r
- Moonlight.Algebra: extGcd :: GCDDomain a => a -> a -> (a, a, a)
- Moonlight.Algebra: extendLinear :: (Eq r, Ring r, Ord targetBasis) => (sourceBasis -> SparseVec r targetBasis) -> SparseVec r sourceBasis -> SparseVec r targetBasis
- Moonlight.Algebra: extendedGcdDomain :: GCDDomain a => a -> a -> (a, a, a)
- Moonlight.Algebra: flipOrientation :: Orientation -> Orientation
- Moonlight.Algebra: fromBool :: BoundedLattice a => Bool -> a
- Moonlight.Algebra: fromCoefficients :: (Eq r, AdditiveMonoid r) => [r] -> Polynomial r
- Moonlight.Algebra: fromEntries :: (Eq r, AdditiveMonoid r, Ord g) => [(g, r)] -> SparseVec r g
- Moonlight.Algebra: fromList :: Ord a => [a] -> PowerSet a
- Moonlight.Algebra: fromTerms :: Ord g => [(g, Integer)] -> FreeAbelianGroup g
- Moonlight.Algebra: gcd :: GCDDomain a => a -> a -> a
- Moonlight.Algebra: gcdDomain :: GCDDomain a => a -> a -> a
- Moonlight.Algebra: generator :: FreeModule scalar moduleValue => Basis scalar moduleValue -> moduleValue
- Moonlight.Algebra: greatestFixpoint :: (Eq a, BoundedMeetSemilattice a) => Natural -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: greatestPostFixpoint :: (Eq a, BoundedMeetSemilattice a) => Natural -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: greatestPostFixpointFrom :: (Eq a, MeetSemilattice a) => Natural -> a -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: groupDifference :: Group group => group -> group -> group
- Moonlight.Algebra: groupInverse :: Group group => group -> group
- Moonlight.Algebra: implies :: HeytingAlgebra a => a -> a -> a
- Moonlight.Algebra: infixr 6 <>
- Moonlight.Algebra: isPrime :: Integer -> Bool
- Moonlight.Algebra: isUnit :: IntegralDomain a => a -> Bool
- Moonlight.Algebra: isZero :: IntegralDomain a => a -> Bool
- Moonlight.Algebra: iterateFixpointFrom :: Eq a => Natural -> a -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: join :: JoinSemilattice a => a -> a -> a
- Moonlight.Algebra: joinLeq :: (Eq a, JoinSemilattice a) => a -> a -> Bool
- Moonlight.Algebra: joins :: (BoundedJoinSemilattice a, Foldable foldable) => foldable a -> a
- Moonlight.Algebra: joins1 :: JoinSemilattice a => NonEmpty a -> a
- Moonlight.Algebra: laneCount :: Int
- Moonlight.Algebra: laneVectorFromLanes :: Vector Word64 -> LaneVector
- Moonlight.Algebra: laneVectorLanes :: LaneVector -> Vector Word64
- Moonlight.Algebra: laneVectorZero :: LaneVector
- Moonlight.Algebra: leastFixpoint :: (Eq a, BoundedJoinSemilattice a) => Natural -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: leastPreFixpoint :: (Eq a, BoundedJoinSemilattice a) => Natural -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: leastPreFixpointFrom :: (Eq a, JoinSemilattice a) => Natural -> a -> (a -> a) -> Either (FixpointDivergence a) a
- Moonlight.Algebra: lookupEntry :: (AdditiveMonoid r, Ord g) => g -> SparseVec r g -> r
- Moonlight.Algebra: mappend :: Monoid a => a -> a -> a
- Moonlight.Algebra: mconcat :: Monoid a => [a] -> a
- Moonlight.Algebra: meet :: MeetSemilattice a => a -> a -> a
- Moonlight.Algebra: meetLeq :: (Eq a, MeetSemilattice a) => a -> a -> Bool
- Moonlight.Algebra: meets :: (BoundedMeetSemilattice a, Foldable foldable) => foldable a -> a
- Moonlight.Algebra: meets1 :: MeetSemilattice a => NonEmpty a -> a
- Moonlight.Algebra: member :: Ord a => a -> PowerSet a -> Bool
- Moonlight.Algebra: mempty :: Monoid a => a
- Moonlight.Algebra: mkCanonicalResidue :: CanonicalEuclideanDomain a => NonZeroModulus modulus a -> a -> CanonicalResidue modulus a
- Moonlight.Algebra: mkNonZeroDivisor :: IntegralDomain a => a -> Maybe (NonZeroDivisor a)
- Moonlight.Algebra: mkProductAlgebra :: forall (n :: Nat) a. KnownNat n => [a] -> Maybe (ProductAlgebra n a)
- Moonlight.Algebra: mkZn :: forall (n :: Nat). (KnownNat n, 1 <= n) => Integer -> Zn n
- Moonlight.Algebra: mobiusValue :: Integer -> Integer
- Moonlight.Algebra: modInverse :: CanonicalEuclideanDomain a => a -> NonZeroModulus modulus a -> Maybe a
- Moonlight.Algebra: monomial :: (Eq r, AdditiveMonoid r) => Natural -> r -> Polynomial r
- Moonlight.Algebra: multiplyQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a -> Quotient modulus a -> Quotient modulus a
- Moonlight.Algebra: neg :: HeytingAlgebra a => a -> a
- Moonlight.Algebra: negateQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a -> Quotient modulus a
- Moonlight.Algebra: newtype Additive a
- Moonlight.Algebra: newtype Batch a
- Moonlight.Algebra: newtype ChainOrder a
- Moonlight.Algebra: newtype Join a
- Moonlight.Algebra: newtype Lukasiewicz a
- Moonlight.Algebra: newtype Meet a
- Moonlight.Algebra: newtype Multiplicative a
- Moonlight.Algebra: newtype Viterbi a
- Moonlight.Algebra: nonZeroDivisorValue :: NonZeroDivisor a -> a
- Moonlight.Algebra: normalize :: (Eq r, AdditiveMonoid r, Ord g) => SparseVec r g -> SparseVec r g
- Moonlight.Algebra: normalizeFreeAbelianGroup :: Ord g => FreeAbelianGroup g -> FreeAbelianGroup g
- Moonlight.Algebra: normalizePolynomial :: Polynomial r -> Polynomial r
- Moonlight.Algebra: normalizePowerSet :: Ord a => PowerSet a -> PowerSet a
- Moonlight.Algebra: obstructionMagnitude :: HasMagnitude obstruction => obstruction -> Double
- Moonlight.Algebra: oneQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a
- Moonlight.Algebra: primePowerFactors :: Integer -> [(Integer, Int)]
- Moonlight.Algebra: primePowerPart :: Integer -> Integer -> Integer
- Moonlight.Algebra: quadraticForm :: BilinearSpace scalar vector => vector -> scalar
- Moonlight.Algebra: quotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> a -> Quotient modulus a
- Moonlight.Algebra: quotientRepresentative :: Quotient modulus a -> a
- Moonlight.Algebra: residual :: ResiduatedQuantale a => a -> a -> a
- Moonlight.Algebra: scale :: Module scalar moduleValue => scalar -> moduleValue -> moduleValue
- Moonlight.Algebra: singleton :: Ord g => g -> Integer -> FreeAbelianGroup g
- Moonlight.Algebra: singletonBatch :: a -> Batch a
- Moonlight.Algebra: sparseIxVecFromEntries :: (Eq r, AdditiveMonoid r) => [(Int, r)] -> SparseIxVec r
- Moonlight.Algebra: sparseIxVecToEntries :: SparseIxVec r -> [(Int, r)]
- Moonlight.Algebra: sparseLinearMapToEntries :: SparseLinearMap r -> [(Int, Int, r)]
- Moonlight.Algebra: subtractQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a -> Quotient modulus a -> Quotient modulus a
- Moonlight.Algebra: support :: FreeModule scalar moduleValue => moduleValue -> [Basis scalar moduleValue]
- Moonlight.Algebra: symmetricDifference :: BooleanAlgebra a => a -> a -> a
- Moonlight.Algebra: tensor :: Quantale a => a -> a -> a
- Moonlight.Algebra: tensorUnit :: Quantale a => a
- Moonlight.Algebra: tensors :: (Quantale a, Foldable foldable) => foldable a -> a
- Moonlight.Algebra: toCoefficients :: AdditiveMonoid r => Polynomial r -> [r]
- Moonlight.Algebra: toEntries :: SparseVec r g -> [(g, r)]
- Moonlight.Algebra: toPowerSetList :: PowerSet a -> [a]
- Moonlight.Algebra: toProductList :: forall (n :: Nat) a. ProductAlgebra n a -> [a]
- Moonlight.Algebra: toTerms :: FreeAbelianGroup g -> [(g, Integer)]
- Moonlight.Algebra: top :: BoundedMeetSemilattice a => a
- Moonlight.Algebra: totalObstructionMagnitude :: HasMagnitude obstruction => Validation (NonEmpty obstruction) value -> Double
- Moonlight.Algebra: type Basis scalar moduleValue;
- Moonlight.Algebra: type BoundedLattice a = (Lattice a, BoundedJoinSemilattice a, BoundedMeetSemilattice a)
- Moonlight.Algebra: type Degree a;
- Moonlight.Algebra: type NonZeroDivisor a = NonZero EuclideanDivisor a
- Moonlight.Algebra: type NonZeroModulus modulus a = NonZero modulus a
- Moonlight.Algebra: type family Basis scalar moduleValue
- Moonlight.Algebra: unZn :: forall (n :: Nat). Zn n -> Integer
- Moonlight.Algebra: unitInverse :: IntegralDomain a => a -> Maybe a
- Moonlight.Algebra: withCanonicalResidue :: CanonicalResidue modulus a -> (NonZeroModulus modulus a -> a -> r) -> r
- Moonlight.Algebra: withNonZeroModulus :: IntegralDomain a => a -> (forall modulus. () => NonZeroModulus modulus a -> r) -> Maybe r
- Moonlight.Algebra: withNonZeroModulusValue :: NonZeroModulus modulus a -> (a -> r) -> r
- Moonlight.Algebra: withQuotientContext :: IntegralDomain a => a -> (forall modulus. () => QuotientContext modulus a -> result) -> Maybe result
- Moonlight.Algebra: zeroQuotient :: CanonicalEuclideanDomain a => QuotientContext modulus a -> Quotient modulus a
- Moonlight.Algebra: znModulus :: forall (n :: Nat) proxy. KnownNat n => proxy n -> Integer
- Moonlight.Algebra: }
+ Moonlight.Algebra: ($dmadd) :: (AdditiveMonoid a, Num a) => a -> a -> a
+ Moonlight.Algebra: ($dmmul) :: (MultiplicativeMonoid a, Num a) => a -> a -> a
+ Moonlight.Algebra: ($dmone) :: (MultiplicativeMonoid a, Num a) => a
+ Moonlight.Algebra: ($dmzero) :: (AdditiveMonoid a, Num a) => a
Files
- CHANGELOG.md +6/−0
- moonlight-algebra.cabal +19/−1
- src-abstract/Moonlight/Algebra/Pure/Lattice.hs +7/−83
- src-join/Moonlight/Algebra/Pure/Join.hs +109/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog +## 0.1.1.0 - 2026-09-23++- Extract the existing join-semilattice law and standard instances into the+ dependency-light public `join` sublibrary. The full lattice tower reexports+ that exact owner rather than compiling a second class.+ ## 0.1.0.2 - 2026-08-21 - Add the public quantale tower: `Quantale`, commutative, residuated, integral,
moonlight-algebra.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.4 name: moonlight-algebra-version: 0.1.0.2+version: 0.1.1.0 homepage: https://github.com/PaleRoses/moonlight bug-reports: https://github.com/PaleRoses/moonlight/issues synopsis: Algebraic type class tower for Pale Meridian.@@ -23,6 +23,12 @@ location: https://github.com/PaleRoses/moonlight.git subdir: moonlight-algebra +source-repository this+ type: git+ location: https://github.com/PaleRoses/moonlight.git+ tag: moonlight-algebra-0.1.1.0+ subdir: moonlight-algebra+ common shared-properties default-language: GHC2024 ghc-options:@@ -37,6 +43,17 @@ TypeFamilies UndecidableInstances +library join+ import: shared-properties+ default-language: GHC2021+ visibility: public+ hs-source-dirs: src-join+ exposed-modules:+ Moonlight.Algebra.Pure.Join+ build-depends:+ base >= 4.19 && < 5+ , containers >= 0.6 && < 0.9+ library abstract import: shared-properties visibility: public@@ -65,6 +82,7 @@ build-depends: base >= 4.22 && < 5 , containers >= 0.6 && < 0.9+ , moonlight-algebra:join , moonlight-algebra:moonlight-algebra-internal , moonlight-core >= 0.1 && < 0.2 , vector >= 0.13 && < 0.14
src-abstract/Moonlight/Algebra/Pure/Lattice.hs view
@@ -41,6 +41,13 @@ import Data.List.NonEmpty (NonEmpty (..)) import Data.Map.Strict qualified as Map import Data.Set qualified as Set+import Moonlight.Algebra.Pure.Join+ ( BoundedJoinSemilattice (..)+ , Join (..)+ , JoinSemilattice (..)+ , joins+ , joins1+ ) import Moonlight.Core ( FixpointDivergence (..), PartialOrder,@@ -50,85 +57,10 @@ ( Natural, ) -type Join :: Type -> Type-newtype Join a = Join {getJoin :: a}- deriving stock (Eq, Ord, Show)- type Meet :: Type -> Type newtype Meet a = Meet {getMeet :: a} deriving stock (Eq, Ord, Show) -type JoinSemilattice :: Type -> Constraint-class JoinSemilattice a where- join :: a -> a -> a--instance JoinSemilattice () where- join _ _ = ()--instance JoinSemilattice Bool where- join = (||)--instance Ord a => JoinSemilattice (Set.Set a) where- join = Set.union--instance JoinSemilattice IntSet.IntSet where- join = IntSet.union--instance (Ord key, JoinSemilattice value) => JoinSemilattice (Map.Map key value) where- join = Map.unionWith join--instance JoinSemilattice value => JoinSemilattice (IntMap.IntMap value) where- join = IntMap.unionWith join--instance (JoinSemilattice left, JoinSemilattice right) => JoinSemilattice (left, right) where- join (leftA, rightA) (leftB, rightB) =- (join leftA leftB, join rightA rightB)--instance JoinSemilattice value => JoinSemilattice (key -> value) where- join left right key =- join (left key) (right key)--instance JoinSemilattice a => Semigroup (Join a) where- Join left <> Join right =- Join (join left right)--type BoundedJoinSemilattice :: Type -> Constraint-class JoinSemilattice a => BoundedJoinSemilattice a where- bottom :: a--instance BoundedJoinSemilattice () where- bottom = ()--instance BoundedJoinSemilattice Bool where- bottom = False--instance Ord a => BoundedJoinSemilattice (Set.Set a) where- bottom = Set.empty--instance BoundedJoinSemilattice IntSet.IntSet where- bottom = IntSet.empty--instance (Ord key, JoinSemilattice value) => BoundedJoinSemilattice (Map.Map key value) where- bottom = Map.empty--instance JoinSemilattice value => BoundedJoinSemilattice (IntMap.IntMap value) where- bottom = IntMap.empty--instance- (BoundedJoinSemilattice left, BoundedJoinSemilattice right) =>- BoundedJoinSemilattice (left, right)- where- bottom =- (bottom, bottom)--instance BoundedJoinSemilattice value => BoundedJoinSemilattice (key -> value) where- bottom =- const bottom--instance BoundedJoinSemilattice a => Monoid (Join a) where- mempty =- Join bottom- type MeetSemilattice :: Type -> Constraint class MeetSemilattice a where meet :: a -> a -> a@@ -380,14 +312,6 @@ meetLeq :: (Eq a, MeetSemilattice a) => a -> a -> Bool meetLeq left right = meet left right == left--joins :: (BoundedJoinSemilattice a, Foldable foldable) => foldable a -> a-joins =- foldl' join bottom--joins1 :: JoinSemilattice a => NonEmpty a -> a-joins1 (first :| rest) =- foldl' join first rest meets :: (BoundedMeetSemilattice a, Foldable foldable) => foldable a -> a meets =
+ src-join/Moonlight/Algebra/Pure/Join.hs view
@@ -0,0 +1,109 @@+{-# LANGUAGE DerivingStrategies #-}++-- | The dependency-light join-semilattice owner.+--+-- 'join' is associative, commutative, and idempotent. 'bottom' is its+-- identity. Instances are laws, not merely binary combining strategies.+module Moonlight.Algebra.Pure.Join+ ( JoinSemilattice (..)+ , BoundedJoinSemilattice (..)+ , Join (..)+ , joins+ , joins1+ ) where++import Data.IntMap.Strict qualified as IntMap+import Data.IntSet qualified as IntSet+import Data.Foldable qualified as Foldable+import Data.Kind (Constraint, Type)+import Data.List.NonEmpty (NonEmpty (..))+import Data.Map.Strict qualified as Map+import Data.Set qualified as Set++-- | Select the join operation as a standard 'Semigroup' or 'Monoid'.+type Join :: Type -> Type+newtype Join a = Join {getJoin :: a}+ deriving stock (Eq, Ord, Show)++type JoinSemilattice :: Type -> Constraint+-- | Values admitting a lawful least upper bound.+class JoinSemilattice a where+ -- | Associative, commutative, and idempotent join.+ join :: a -> a -> a++instance JoinSemilattice () where+ join _ _ = ()++instance JoinSemilattice Bool where+ join = (||)++instance Ord a => JoinSemilattice (Set.Set a) where+ join = Set.union++instance JoinSemilattice IntSet.IntSet where+ join = IntSet.union++instance (Ord key, JoinSemilattice value) => JoinSemilattice (Map.Map key value) where+ join = Map.unionWith join++instance JoinSemilattice value => JoinSemilattice (IntMap.IntMap value) where+ join = IntMap.unionWith join++instance (JoinSemilattice left, JoinSemilattice right) => JoinSemilattice (left, right) where+ join (leftA, rightA) (leftB, rightB) =+ (join leftA leftB, join rightA rightB)++instance JoinSemilattice value => JoinSemilattice (key -> value) where+ join left right key =+ join (left key) (right key)++instance JoinSemilattice a => Semigroup (Join a) where+ Join left <> Join right =+ Join (join left right)++type BoundedJoinSemilattice :: Type -> Constraint+-- | A join-semilattice with an identity element.+class JoinSemilattice a => BoundedJoinSemilattice a where+ -- | The least element: @join bottom value == value@.+ bottom :: a++instance BoundedJoinSemilattice () where+ bottom = ()++instance BoundedJoinSemilattice Bool where+ bottom = False++instance Ord a => BoundedJoinSemilattice (Set.Set a) where+ bottom = Set.empty++instance BoundedJoinSemilattice IntSet.IntSet where+ bottom = IntSet.empty++instance (Ord key, JoinSemilattice value) => BoundedJoinSemilattice (Map.Map key value) where+ bottom = Map.empty++instance JoinSemilattice value => BoundedJoinSemilattice (IntMap.IntMap value) where+ bottom = IntMap.empty++instance+ (BoundedJoinSemilattice left, BoundedJoinSemilattice right) =>+ BoundedJoinSemilattice (left, right)+ where+ bottom =+ (bottom, bottom)++instance BoundedJoinSemilattice value => BoundedJoinSemilattice (key -> value) where+ bottom =+ const bottom++instance BoundedJoinSemilattice a => Monoid (Join a) where+ mempty =+ Join bottom++joins :: (BoundedJoinSemilattice a, Foldable foldable) => foldable a -> a+joins =+ Foldable.foldl' join bottom++joins1 :: JoinSemilattice a => NonEmpty a -> a+joins1 (first :| rest) =+ Foldable.foldl' join first rest