cantor-pairing 0.2.0.1 → 0.2.0.2
raw patch · 3 files changed
+16/−12 lines, 3 filesdep −mtldep ~basedep ~containersdep ~integer-gmpPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies removed: mtl
Dependency ranges changed: base, containers, integer-gmp
API changes (from Hackage documentation)
- Cantor: instance Cantor.Cantor a => Cantor.Cantor (Data.Semigroup.Option a)
- Cantor: instance Cantor.Finite a => Cantor.Finite (Data.Semigroup.Option a)
Files
- cantor-pairing.cabal +2/−3
- src/Cantor.hs +13/−8
- test/Spec.hs +1/−1
cantor-pairing.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: cantor-pairing-version: 0.2.0.1+version: 0.2.0.2 synopsis: Convert data to and from a natural number representation description: Convert data to and from a natural number representation conveniently using GHC Generics. homepage: https://github.com/identicalsnowflake/cantor-pairing@@ -24,7 +24,7 @@ Cantor.Huge build-depends: base >= 4.12.0.0 && < 5 , containers >= 0.6.0.1 && < 0.7- , integer-gmp ^>= 1.0.2.0+ , integer-gmp >= 1.0.2.0 && < 1.2 , integer-logarithms >= 1.0.2.2 && < 2.0 , integer-roots >= 1.0 && < 1.1 hs-source-dirs: src@@ -40,7 +40,6 @@ , cantor-pairing , containers , hspec >= 2 && < 3- , mtl >= 2.2.2 build-tool-depends: hspec-discover:hspec-discover default-language: Haskell2010
src/Cantor.hs view
@@ -14,19 +14,25 @@ {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE ViewPatterns #-} --- | Cantor pairing gives us an isomorphism between a single natural number and pairs of natural numbers. This package provides a modern API to this functionality using GHC generics, allowing the encoding of arbitrary combinations of finite or countably infinite types in natural number form.------ As a user, all you need to do is derive generic and get the instances for free.+-- | This package implements a beefed-up version of `Enum` via GHC generics called `Cantor` which works for both finite and countably-infinite types. -- -- = Example -- @ -- import GHC.Generics -- import Cantor---+-- -- data MyType = MyType { -- value1 :: [ Maybe Bool ] -- , value2 :: Integer--- } deriving (Generic,Cantor)+-- } deriving (Generic,Cantor,Show)+-- +-- example :: IO ()+-- example = do+-- putStrLn "The first 5 elements of the enumeration are:"+-- print $ take 5 xs+-- where+-- xs :: [ MyType ]+-- xs = cantorEnumeration -- @ -- -- = Recursive example@@ -58,7 +64,8 @@ -- cardinality = Countable -- instance Cantor Bar -- @-+--+-- Once you have a valid instance of @Cantor a@, you may lazily inspect all values of the type using @cantorEnumeration :: [ a ]@ and convert a point to and from its integer encoding using @toCantor :: Integer -> a@ and @fromCantor :: a -> Integer@. module Cantor ( cantorEnumeration@@ -372,7 +379,6 @@ instance Cantor a => Cantor (First a) instance Cantor a => Cantor (Identity a) instance Cantor a => Cantor (Data.Functor.Const.Const a b)-instance Cantor a => Cantor (Option a) instance Cantor a => Cantor (Min a) instance Cantor a => Cantor (Max a) instance Cantor (Proxy a)@@ -394,7 +400,6 @@ instance Finite a => Finite (First a) instance Finite a => Finite (Identity a) instance Finite a => Finite (Data.Functor.Const.Const a b)-instance Finite a => Finite (Option a) instance Finite a => Finite (Min a) instance Finite a => Finite (Max a) instance Finite (Proxy a)
test/Spec.hs view
@@ -41,7 +41,7 @@ it "returns 6 for the cardinality of Bool x C" $ (fCardinality @(Bool , C)) `shouldBe` 6 - it "returns 9 for the cardinality of C x Bool" $+ it "returns 6 for the cardinality of C x Bool" $ (fCardinality @(C , Bool)) `shouldBe` 6 it "returns 0 for the cardinality of Void x Bool" $