alg 0.2.1.0 → 0.2.2.0
raw patch · 3 files changed
+135/−2 lines, 3 filesdep +util
Dependencies added: util
Files
- Data/BitSet.hs +38/−0
- Relation/Binary/Comparison.hs +93/−1
- alg.cabal +4/−1
+ Data/BitSet.hs view
@@ -0,0 +1,38 @@+module Data.BitSet where++import Control.Applicative+import Control.Monad (guard)+import Data.Bits+import Data.List (concatMap)+import Data.Maybe+import Prelude ((==))+import qualified Prelude as Base+import Util.Bits++import Algebra+import Relation.Binary.Comparison++newtype BitSet a = BitSet { bits :: a }+ deriving (Base.Eq, Bits, FiniteBits, Base.Read, Base.Show)++instance Bits a => Preord (BitSet a) where+ BitSet x ≤ BitSet y = x .&. y == x++instance Bits a => PartialEq (BitSet a) where (≡) = (==)++instance Bits a => Eq (BitSet a)+instance Bits a => PartialOrd (BitSet a)++instance Bits a => Semigroup (BitSet a) where (<>) = xor+instance Bits a => Abelian (BitSet a)+instance Bits a => Monoid (BitSet a) where+ mappend = (<>)+ mempty = zeroBits+instance Bits a => Group (BitSet a) where invert = complement++rangeInclusive :: (PartialOrd a, Bits a) => a -> a -> [a]+rangeInclusive = \ x y -> go y x <* guard (x ≤ y)+ where go y x = x : concatMap (go y) (setBit x <$> setBits (y .&¬ x))++(.&?¬) :: (PartialOrd a, Bits a) => a -> a -> Maybe a+a .&?¬ b = a .&¬ b <$ guard (b ≤ a)
Relation/Binary/Comparison.hs view
@@ -3,7 +3,7 @@ module Relation.Binary.Comparison where -import Prelude (Integer)+import Prelude (Char, Integer) import qualified Prelude import Algebra@@ -12,10 +12,14 @@ import Data.Bool import Data.Either import Data.Function (flip, on)+import Data.Int import Data.Maybe import Data.Ord (Ordering (..))+import Data.Word import Numeric.Natural +infix 4 ≤, ≥, <, >, ≡, ≢+ class Preord a where (≤), (≥), (<), (>) :: a -> a -> Bool (≤) = flip (≥)@@ -75,6 +79,94 @@ instance PartialOrd Integer where tryCompare a b = Just (Prelude.compare a b) instance Eq Integer instance Ord Integer++instance Preord Int where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Int where (≡) = (Prelude.==)+instance PartialOrd Int where tryCompare a b = Just (Prelude.compare a b)+instance Eq Int+instance Ord Int++instance Preord Int8 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Int8 where (≡) = (Prelude.==)+instance PartialOrd Int8 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Int8+instance Ord Int8++instance Preord Int16 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Int16 where (≡) = (Prelude.==)+instance PartialOrd Int16 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Int16+instance Ord Int16++instance Preord Int32 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Int32 where (≡) = (Prelude.==)+instance PartialOrd Int32 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Int32+instance Ord Int32++instance Preord Int64 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Int64 where (≡) = (Prelude.==)+instance PartialOrd Int64 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Int64+instance Ord Int64++instance Preord Word where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Word where (≡) = (Prelude.==)+instance PartialOrd Word where tryCompare a b = Just (Prelude.compare a b)+instance Eq Word+instance Ord Word++instance Preord Word8 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Word8 where (≡) = (Prelude.==)+instance PartialOrd Word8 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Word8+instance Ord Word8++instance Preord Word16 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Word16 where (≡) = (Prelude.==)+instance PartialOrd Word16 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Word16+instance Ord Word16++instance Preord Word32 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Word32 where (≡) = (Prelude.==)+instance PartialOrd Word32 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Word32+instance Ord Word32++instance Preord Word64 where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Word64 where (≡) = (Prelude.==)+instance PartialOrd Word64 where tryCompare a b = Just (Prelude.compare a b)+instance Eq Word64+instance Ord Word64++instance Preord Char where+ (≤) = (Prelude.<=)+ (<) = (Prelude.<)+instance PartialEq Char where (≡) = (Prelude.==)+instance PartialOrd Char where tryCompare a b = Just (Prelude.compare a b)+instance Eq Char+instance Ord Char instance (PartialEq a, PartialEq b) => PartialEq (a, b) where (aₗ, bₗ) ≡ (aᵣ, bᵣ) = aₗ ≡ aᵣ && bₗ ≡ bᵣ
alg.cabal view
@@ -1,5 +1,5 @@ name: alg-version: 0.2.1.0+version: 0.2.2.0 synopsis: Algebraic structures -- description: license: BSD3@@ -16,10 +16,12 @@ library exposed-modules: Algebra+ , Data.BitSet , Relation.Binary.Comparison -- other-modules: other-extensions: build-depends: base >=4.9 && <5+ , util >=0.1.5 && <0.2 -- hs-source-dirs: default-language: Haskell2010 default-extensions: NoImplicitPrelude@@ -28,4 +30,5 @@ , TypeOperators , ConstraintKinds , PolyKinds+ , GeneralizedNewtypeDeriving ghc-options: -Wall