cantor-pairing alternatives and similar packages
Based on the "Data" category.
Alternatively, view cantor-pairing alternatives based on common mentions on social networks and blogs.
-
streaming
An optimized general monad transformer for streaming applications, with a simple prelude of functions -
text-icu
This package provides the Haskell Data.Text.ICU library, for performing complex manipulation of Unicode text.
InfluxDB - Power Real-Time Data Analytics at Scale
Do you think we are missing an alternative of cantor-pairing or a related project?
README
cantor-pairing
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.
Example
import GHC.Generics
import Cantor
data MyType = MyType {
value1 :: [ Maybe Bool ]
, value2 :: Integer
} deriving (Generic,Cantor)
This should work nicely even with simple inductive types:
Recursive example
data Tree a = Leaf | Branch (Tree a) a (Tree a) deriving (Generic,Cantor)
If your type is finite, you can specify this by deriving the Finite
typeclass, which is a subclass of Cantor
:
Finite example
data Color = Red | Green | Blue deriving (Generic,Cantor,Finite)
Mutually-recursive types
If you have mutually-recursive types, unfortunately you'll need to manually specify the cardinality for now, but you can still get the to/from encodings for free:
data Foo = FooNil | Foo Bool Bar deriving (Generic,Show)
data Bar = BarNil | Bar Bool Foo deriving (Generic,Show)
instance Cantor Foo where
cardinality = Countable
instance Cantor Bar