universe-1.1.1: A class for finite and recursively enumerable types.

Safe HaskellNone
LanguageHaskell2010

Data.Universe

Description

A convenience module that imports the submodules Instances.Base, Instances.Containers, Instances.Extended, and Instances.Trans to provide instances of Universe and Finite for a wide variety of types.

Synopsis

Documentation

class Universe a where #

Creating an instance of this class is a declaration that your type is recursively enumerable (and that universe is that enumeration). In particular, you promise that any finite inhabitant has a finite index in universe, and that no inhabitant appears at two different finite indices.

Well-behaved instance should produce elements lazily.

Laws:

elem x universe                    -- any inhabitant has a finite index
let pfx = take n universe          -- any finite prefix of universe has unique elements
in length pfx = length (nub pfx)

Minimal complete definition

Nothing

Methods

universe :: [a] #

Instances
Universe Bool 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Bool] #

Universe Char 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Char] #

Universe Int 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Int] #

Universe Int8 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Int8] #

Universe Int16 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Int16] #

Universe Int32 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Int32] #

Universe Int64 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Int64] #

Universe Integer 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Integer] #

Universe Natural 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Natural] #

Universe Ordering 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Ordering] #

Universe Word 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Word] #

Universe Word8 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Word8] #

Universe Word16 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Word16] #

Universe Word32 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Word32] #

Universe Word64 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Word64] #

Universe () 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [()] #

Universe Void 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Void] #

Universe All 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [All] #

Universe Any 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Any] #

Universe a => Universe [a] 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [[a]] #

Universe a => Universe (Maybe a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Maybe a] #

RationalUniverse a => Universe (Ratio a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Ratio a] #

Universe a => Universe (Min a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Min a] #

Universe a => Universe (Max a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Max a] #

Universe a => Universe (First a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [First a] #

Universe a => Universe (Last a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Last a] #

Universe a => Universe (Identity a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Identity a] #

Universe a => Universe (First a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [First a] #

Universe a => Universe (Last a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Last a] #

Universe a => Universe (Dual a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Dual a] #

Universe a => Universe (Sum a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Sum a] #

Universe a => Universe (Product a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Product a] #

Universe a => Universe (NonEmpty a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [NonEmpty a] #

(Ord a, Universe a) => Universe (Set a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Set a] #

(Finite a, Ord a, Universe b) => Universe (a -> b) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [a -> b] #

(Universe a, Universe b) => Universe (Either a b) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Either a b] #

(Universe a, Universe b) => Universe (a, b) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [(a, b)] #

Universe (Proxy a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Proxy a] #

(Ord k, Finite k, Universe v) => Universe (Map k v) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Map k v] #

(Universe a, Universe b, Universe c) => Universe (a, b, c) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [(a, b, c)] #

Universe a => Universe (Const a b) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Const a b] #

Universe (f a) => Universe (IdentityT f a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [IdentityT f a] #

Universe a => Universe (Tagged b a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Tagged b a] #

(Universe a, Universe b, Universe c, Universe d) => Universe (a, b, c, d) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [(a, b, c, d)] #

(Universe (f a), Universe (g a)) => Universe (Product f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Product f g a] #

(Universe (f a), Universe (g a)) => Universe (Sum f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Sum f g a] #

(Finite e, Ord e, Universe (m a)) => Universe (ReaderT e m a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [ReaderT e m a] #

(Universe a, Universe b, Universe c, Universe d, Universe e) => Universe (a, b, c, d, e) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [(a, b, c, d, e)] #

Universe (f (g a)) => Universe (Compose f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universe :: [Compose f g a] #

class Universe a => Finite a where #

Creating an instance of this class is a declaration that your universe eventually ends. Minimal definition: no methods defined. By default, universeF = universe, but for some types (like Either) the universeF method may have a more intuitive ordering.

Laws:

elem x universeF                       -- any inhabitant has a finite index
length (filter (== x) universeF) == 1  -- should terminate
(xs -> cardinality xs == genericLength xs) universeF

Note: elemIndex x universe == elemIndex x universeF may not hold for all types, though the laws imply that universe is a permutation of universeF.

>>> elemIndex (Left True :: Either Bool Bool) universe
Just 2
>>> elemIndex (Left True :: Either Bool Bool) universeF
Just 1

Minimal complete definition

Nothing

Instances
Finite Bool 
Instance details

Defined in Data.Universe.Class

Finite Char 
Instance details

Defined in Data.Universe.Class

Finite Int 
Instance details

Defined in Data.Universe.Class

Finite Int8 
Instance details

Defined in Data.Universe.Class

Finite Int16 
Instance details

Defined in Data.Universe.Class

Finite Int32 
Instance details

Defined in Data.Universe.Class

Finite Int64 
Instance details

Defined in Data.Universe.Class

Finite Ordering 
Instance details

Defined in Data.Universe.Class

Finite Word 
Instance details

Defined in Data.Universe.Class

Finite Word8 
Instance details

Defined in Data.Universe.Class

Finite Word16 
Instance details

Defined in Data.Universe.Class

Finite Word32 
Instance details

Defined in Data.Universe.Class

Finite Word64 
Instance details

Defined in Data.Universe.Class

Finite () 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [()] #

cardinality :: Tagged () Natural #

Finite Void 
Instance details

Defined in Data.Universe.Class

Finite All 
Instance details

Defined in Data.Universe.Class

Finite Any 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Maybe a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Min a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Max a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (First a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Last a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Identity a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (First a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Last a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Dual a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Sum a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Product a) 
Instance details

Defined in Data.Universe.Class

(Ord a, Finite a) => Finite (Set a) 
Instance details

Defined in Data.Universe.Class

(Ord a, Finite a, Finite b) => Finite (a -> b) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [a -> b] #

cardinality :: Tagged (a -> b) Natural #

(Finite a, Finite b) => Finite (Either a b) 
Instance details

Defined in Data.Universe.Class

(Finite a, Finite b) => Finite (a, b) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [(a, b)] #

cardinality :: Tagged (a, b) Natural #

Finite (Proxy a) 
Instance details

Defined in Data.Universe.Class

(Ord k, Finite k, Finite v) => Finite (Map k v) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [Map k v] #

cardinality :: Tagged (Map k v) Natural #

(Finite a, Finite b, Finite c) => Finite (a, b, c) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [(a, b, c)] #

cardinality :: Tagged (a, b, c) Natural #

Finite a => Finite (Const a b) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [Const a b] #

cardinality :: Tagged (Const a b) Natural #

Finite (f a) => Finite (IdentityT f a) 
Instance details

Defined in Data.Universe.Class

Finite a => Finite (Tagged b a) 
Instance details

Defined in Data.Universe.Class

(Finite a, Finite b, Finite c, Finite d) => Finite (a, b, c, d) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [(a, b, c, d)] #

cardinality :: Tagged (a, b, c, d) Natural #

(Finite (f a), Finite (g a)) => Finite (Product f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [Product f g a] #

cardinality :: Tagged (Product f g a) Natural #

(Finite (f a), Finite (g a)) => Finite (Sum f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [Sum f g a] #

cardinality :: Tagged (Sum f g a) Natural #

(Finite e, Ord e, Finite (m a)) => Finite (ReaderT e m a) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [ReaderT e m a] #

cardinality :: Tagged (ReaderT e m a) Natural #

(Finite a, Finite b, Finite c, Finite d, Finite e) => Finite (a, b, c, d, e) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [(a, b, c, d, e)] #

cardinality :: Tagged (a, b, c, d, e) Natural #

Finite (f (g a)) => Finite (Compose f g a) 
Instance details

Defined in Data.Universe.Class

Methods

universeF :: [Compose f g a] #

cardinality :: Tagged (Compose f g a) Natural #

universeGeneric :: (Generic a, GUniverse (Rep a)) => [a] #

>>> data Zero deriving (Show, Generic)
>>> universeGeneric :: [Zero]
[]
>>> data One = One deriving (Show, Generic)
>>> universeGeneric :: [One]
[One]
>>> data Big = B0 Bool Bool | B1 Bool deriving (Show, Generic)
>>> universeGeneric :: [Big]
[B0 False False,B1 False,B0 False True,B1 True,B0 True False,B0 True True]
>>> universeGeneric :: [Maybe Ordering]
[Nothing,Just LT,Just EQ,Just GT]
>>> take 10 (universeGeneric :: [Either Integer Integer])
[Left 0,Right 0,Left 1,Right 1,Left (-1),Right (-1),Left 2,Right 2,Left (-2),Right (-2)]
>>> take 10 (universeGeneric :: [(Integer, Integer, Integer)])
[(0,0,0),(0,0,1),(1,0,0),(0,1,0),(1,0,1),(-1,0,0),(0,0,-1),(1,1,0),(-1,0,1),(2,0,0)]