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

Safe Haskell | Safe
Language | Haskell2010

Data.Universe.Class

Description

Bottoms are ignored for this entire module: only fully-defined inhabitants are considered inhabitants.

Synopsis

- class Universe a where
  - universe :: [a]
- class Universe a => Finite a where
  - universeF :: [a]
  - cardinality :: Tagged a Natural

# Documentation

class Universe a where Source #

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] Source #

default universe :: (Enum a, Bounded a) => [a] Source #

#### Instances

Instances details

Universe Void Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Void] Source #
Universe All Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [All] Source #
Universe Any Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Any] Source #
Universe Int16 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Int16] Source #
Universe Int32 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Int32] Source #
Universe Int64 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Int64] Source #
Universe Int8 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Int8] Source #
Universe Word16 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Word16] Source #
Universe Word32 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Word32] Source #
Universe Word64 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Word64] Source #
Universe Word8 Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Word8] Source #
Universe Ordering Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Ordering] Source #
Universe Integer Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Integer] Source #
Universe Natural Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Natural] Source #
Universe () Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [()] Source #
Universe Bool Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Bool] Source #
Universe Char Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Char] Source #
Universe Int Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Int] Source #
Universe Word Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Word] Source #
Universe a => Universe (First a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [First a] Source #
Universe a => Universe (Last a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Last a] Source #
Universe a => Universe (Max a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Max a] Source #
Universe a => Universe (Min a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Min a] Source #

(Ord a, Universe a) => Universe (Set a) Source #

    >>> import qualified Data.Set as Set
    >>> mapM_ print (universe :: [Set.Set Bool])
    fromList []
    fromList [False]
    fromList [True]
    fromList [False,True]

Instance details Defined in Data.Universe.Class Methods universe :: [Set a] Source #
Universe a => Universe (NonEmpty a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [NonEmpty a] Source #
Universe a => Universe (Identity a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Identity a] Source #
Universe a => Universe (First a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [First a] Source #
Universe a => Universe (Last a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Last a] Source #
Universe a => Universe (Dual a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Dual a] Source #
Universe a => Universe (Product a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Product a] Source #
Universe a => Universe (Sum a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Sum a] Source #
RationalUniverse a => Universe (Ratio a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Ratio a] Source #
Universe a => Universe (Maybe a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Maybe a] Source #
Universe a => Universe (Solo a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Solo a] Source #
Universe a => Universe [a] Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [[a]] Source #

(Ord k, Finite k, Universe v) => Universe (Map k v) Source #

    >>> import qualified Data.Map as Map
    >>> mapM_ print (universe :: [Map.Map Bool Bool])
    fromList []
    fromList [(True,False)]
    fromList [(False,False)]
    fromList [(True,True)]
    fromList [(False,False),(True,False)]
    fromList [(False,True)]
    fromList [(False,False),(True,True)]
    fromList [(False,True),(True,False)]
    fromList [(False,True),(True,True)]

Instance details Defined in Data.Universe.Class Methods universe :: [Map k v] Source #
(Universe a, Universe b) => Universe (Either a b) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Either a b] Source #
Universe (Proxy a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Proxy a] Source #
(Universe a, Universe b) => Universe (a, b) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [(a, b)] Source #

(Finite a, Ord a, Universe b) => Universe (a -> b) Source #

    >>> mapM_ print (universe :: [Bool -> Bool])
    [(False,False),(True,False)]
    [(False,False),(True,True)]
    [(False,True),(True,False)]
    [(False,True),(True,True)]

Instance details Defined in Data.Universe.Class Methods universe :: [a -> b] Source #
Universe a => Universe (Const a b) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Const a b] Source #
Universe a => Universe (Tagged b a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Tagged b a] Source #
Universe (f a) => Universe (IdentityT f a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [IdentityT f a] Source #
(Finite e, Ord e, Universe (m a)) => Universe (ReaderT e m a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [ReaderT e m a] Source #
(Universe a, Universe b, Universe c) => Universe (a, b, c) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [(a, b, c)] Source #
(Universe (f a), Universe (g a)) => Universe (Product f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Product f g a] Source #
(Universe (f a), Universe (g a)) => Universe (Sum f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Sum f g a] Source #
(Universe a, Universe b, Universe c, Universe d) => Universe (a, b, c, d) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [(a, b, c, d)] Source #
Universe (f (g a)) => Universe (Compose f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [Compose f g a] Source #
(Universe a, Universe b, Universe c, Universe d, Universe e) => Universe (a, b, c, d, e) Source # |
Instance details Defined in Data.Universe.Class Methods universe :: [(a, b, c, d, e)] Source #

class Universe a => Finite a where Source #

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

Methods

universeF :: [a] Source #

cardinality :: Tagged a Natural Source #

#### Instances

Instances details

Finite Void Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Void] Source # cardinality :: Tagged Void Natural Source #
Finite All Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [All] Source # cardinality :: Tagged All Natural Source #
Finite Any Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Any] Source # cardinality :: Tagged Any Natural Source #
Finite Int16 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Int16] Source # cardinality :: Tagged Int16 Natural Source #
Finite Int32 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Int32] Source # cardinality :: Tagged Int32 Natural Source #
Finite Int64 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Int64] Source # cardinality :: Tagged Int64 Natural Source #
Finite Int8 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Int8] Source # cardinality :: Tagged Int8 Natural Source #
Finite Word16 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Word16] Source # cardinality :: Tagged Word16 Natural Source #
Finite Word32 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Word32] Source # cardinality :: Tagged Word32 Natural Source #
Finite Word64 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Word64] Source # cardinality :: Tagged Word64 Natural Source #
Finite Word8 Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Word8] Source # cardinality :: Tagged Word8 Natural Source #
Finite Ordering Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Ordering] Source # cardinality :: Tagged Ordering Natural Source #
Finite () Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [()] Source # cardinality :: Tagged () Natural Source #
Finite Bool Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Bool] Source # cardinality :: Tagged Bool Natural Source #
Finite Char Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Char] Source # cardinality :: Tagged Char Natural Source #
Finite Int Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Int] Source # cardinality :: Tagged Int Natural Source #
Finite Word Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Word] Source # cardinality :: Tagged Word Natural Source #
Finite a => Finite (First a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [First a] Source # cardinality :: Tagged (First a) Natural Source #
Finite a => Finite (Last a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Last a] Source # cardinality :: Tagged (Last a) Natural Source #
Finite a => Finite (Max a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Max a] Source # cardinality :: Tagged (Max a) Natural Source #
Finite a => Finite (Min a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Min a] Source # cardinality :: Tagged (Min a) Natural Source #
(Ord a, Finite a) => Finite (Set a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Set a] Source # cardinality :: Tagged (Set a) Natural Source #
Finite a => Finite (Identity a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Identity a] Source # cardinality :: Tagged (Identity a) Natural Source #
Finite a => Finite (First a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [First a] Source # cardinality :: Tagged (First a) Natural Source #
Finite a => Finite (Last a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Last a] Source # cardinality :: Tagged (Last a) Natural Source #
Finite a => Finite (Dual a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Dual a] Source # cardinality :: Tagged (Dual a) Natural Source #
Finite a => Finite (Product a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Product a] Source # cardinality :: Tagged (Product a) Natural Source #
Finite a => Finite (Sum a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Sum a] Source # cardinality :: Tagged (Sum a) Natural Source #
Finite a => Finite (Maybe a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Maybe a] Source # cardinality :: Tagged (Maybe a) Natural Source #
Finite a => Finite (Solo a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Solo a] Source # cardinality :: Tagged (Solo a) Natural Source #
(Ord k, Finite k, Finite v) => Finite (Map k v) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Map k v] Source # cardinality :: Tagged (Map k v) Natural Source #
(Finite a, Finite b) => Finite (Either a b) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Either a b] Source # cardinality :: Tagged (Either a b) Natural Source #
Finite (Proxy a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Proxy a] Source # cardinality :: Tagged (Proxy a) Natural Source #
(Finite a, Finite b) => Finite (a, b) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [(a, b)] Source # cardinality :: Tagged (a, b) Natural Source #

(Ord a, Finite a, Finite b) => Finite (a -> b) Source #

    >>> mapM_ print (universeF :: [Bool -> Bool])
    [(False,False),(True,False)]
    [(False,False),(True,True)]
    [(False,True),(True,False)]
    [(False,True),(True,True)]

    >>> cardinality :: Tagged (Bool -> Ordering) Natural
    Tagged 9

    >>> cardinality :: Tagged (Ordering -> Bool) Natural
    Tagged 8

Instance details Defined in Data.Universe.Class Methods universeF :: [a -> b] Source # cardinality :: Tagged (a -> b) Natural Source #
Finite a => Finite (Const a b) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Const a b] Source # cardinality :: Tagged (Const a b) Natural Source #
Finite a => Finite (Tagged b a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Tagged b a] Source # cardinality :: Tagged (Tagged b a) Natural Source #
Finite (f a) => Finite (IdentityT f a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [IdentityT f a] Source # cardinality :: Tagged (IdentityT f a) Natural Source #
(Finite e, Ord e, Finite (m a)) => Finite (ReaderT e m a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [ReaderT e m a] Source # cardinality :: Tagged (ReaderT e m a) Natural Source #
(Finite a, Finite b, Finite c) => Finite (a, b, c) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [(a, b, c)] Source # cardinality :: Tagged (a, b, c) Natural Source #
(Finite (f a), Finite (g a)) => Finite (Product f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Product f g a] Source # cardinality :: Tagged (Product f g a) Natural Source #
(Finite (f a), Finite (g a)) => Finite (Sum f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Sum f g a] Source # cardinality :: Tagged (Sum f g a) Natural Source #
(Finite a, Finite b, Finite c, Finite d) => Finite (a, b, c, d) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [(a, b, c, d)] Source # cardinality :: Tagged (a, b, c, d) Natural Source #
Finite (f (g a)) => Finite (Compose f g a) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [Compose f g a] Source # cardinality :: Tagged (Compose f g a) Natural Source #
(Finite a, Finite b, Finite c, Finite d, Finite e) => Finite (a, b, c, d, e) Source # |
Instance details Defined in Data.Universe.Class Methods universeF :: [(a, b, c, d, e)] Source # cardinality :: Tagged (a, b, c, d, e) Natural Source #