finitary-1.0.0.0: A better, more type-safe Enum.
Copyright (C) Koz Ross 2019 GPL version 3.0 or later koz.ross@retro-freedom.nz Experimental GHC only Trustworthy Haskell2010

Data.Finitary

Description

This package provides the Finitary type class, as well as a range of useful 'base' instances for commonly-used finitary types.

For your own types, there are three possible ways to define an instance of Finitary:

Via Generic

If your data type implements Generic (and is finitary), you can automatically derive your instance:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics
import Data.Word

data Foo = Bar | Baz (Word8, Word8) | Quux Word16
deriving (Eq, Generic, Finitary)

This is the easiest method, and also the safest, as GHC will automatically determine the cardinality of Foo, as well as defining law-abiding methods. It may be somewhat slower than a 'hand-rolled' method in some cases.

By defining only Cardinality, fromFinite and toFinite

If you want a manually-defined instance, but don't wish to define every method, only fromFinite and toFinite are needed, along with Cardinality. Cardinality in particular must be defined with care, as otherwise, you may end up with inconstructable values or indexes that don't correspond to anything.

By defining everything

For maximum control, you can define all the methods. Ensure you follow all the laws!

Synopsis

# Documentation

class (Eq a, KnownNat (Cardinality a)) => Finitary (a :: Type) where Source #

Witnesses an isomorphism between a and some (KnownNat n) => Finite n. Effectively, a lawful instance of this shows that a has exactly n (non-_|_) inhabitants, and that we have a bijection with fromFinite and toFinite as each 'direction'.

For any type a with an instance of Finitary, for every non-_|_ x :: a, we have a unique index i :: Finite n. We will also refer to any such x as an inhabitant of a. We can convert inhabitants to indexes using toFinite, and also convert indexes to inhabitants with fromFinite.

Laws

The main laws state that fromFinite should be a bijection, with toFinite as its inverse, and Cardinality must be a truthful representation of the cardinality of the type. Thus:

• $\texttt{fromFinite} \circ \texttt{toFinite} = \texttt{toFinite} \circ \texttt{fromFinite} = \texttt{id}$
• $\forall x, y :: \texttt{Finite} \; (\texttt{Cardinality} \; a) \; \texttt{fromFinite} \; x = \texttt{fromFinite} \; y \rightarrow x = y$
• $\forall x :: \texttt{Finite} \; (\texttt{Cardinality} \; a) \; \exists y :: a \mid \texttt{fromFinite} \; x = y$

Furthermore, fromFinite should be _order-preserving_. Namely, if a is an instance of Ord, we must have:

• $\forall i, j :: \texttt{Finite} \; (\texttt{Cardinality} \; a) \; \texttt{fromFinite} \; i \leq \texttt{fromFinite} \; j \rightarrow i \leq j$

Lastly, if you define any of the other methods, these laws must hold:

• $a \neq \emptyset \rightarrow \texttt{start} = \texttt{fromFinite} \; \texttt{minBound}$
• $a \neq \emptyset \rightarrow \texttt{end} = \texttt{fromFinite} \; \texttt{maxBound}$
• $\forall x :: a \; \texttt{end} \neq x \rightarrow \texttt{next} \; x = (\texttt{fromFinite} \circ + 1 \circ \texttt{toFinite}) \; x$
• $\forall i :: \texttt{Finite} \; (\texttt{Cardinality} \; a) \; \texttt{nextSkipping} \; i = \underbrace{\texttt{next} \circ \ldots \circ \texttt{next}}_{i}$
• $\forall x :: a \; \texttt{start} \neq x \rightarrow \texttt{previous} \; x = (\texttt{fromFinite} \circ - 1 \circ \texttt{toFinite}) \; x$
• $\forall i :: \texttt{Finite} \; (\texttt{Cardinality} \; a) \; \texttt{previousSkipping} \; i = \underbrace{\texttt{previous} \circ \ldots \circ \texttt{previous}}_{i}$
• $\forall x :: a \; \texttt{enumerateFrom} \; x = \texttt{fromFinite <\> [toFinite} \; x \texttt{..]}$
• $\forall x, y :: a \; \texttt{enumerateFromThen} \; x y = \texttt{fromFinite <\> [toFinite} \; x \texttt{, }\; y \texttt{..]}$
• $\forall x, y :: a \; \texttt{enumerateFromTo} \; x \; y = \texttt{fromFinite <\> [toFinite} \; x \texttt{..} \; y \texttt{]}$
• $\forall x, y, z :: a \; \texttt{enumerateFromThenTo} \; x \; y \; z = \texttt{fromFinite <\> [toFinite} \; x \texttt{,} \; y \texttt{..} \; z \texttt{]}$

Together with the fact that Finite n is well-ordered whenever KnownNat n holds, a law-abiding Finitary instance for a type a defines a constructive well-order, witnessed by toFinite and fromFinite, which agrees with the Ord instance for a, if any.

We strongly suggest that fromFinite and toFinite should have time complexity $$\Theta(1)$$, or, if that's not possible, $$O(\texttt{Cardinality} \; a)$$. The latter is the case for instances generated using Generics-based derivation, but not for 'basic' types; thus, these functions for your derived types will only be as slow as their 'structure', rather than their 'contents', provided the contents are of these 'basic' types.

Minimal complete definition

Nothing

Associated Types

type Cardinality a :: Nat Source #

How many (non-_|_) inhabitants a has, as a typelevel natural number.

type Cardinality a = GCardinality (Rep a) Source #

Methods

fromFinite :: Finite (Cardinality a) -> a Source #

Converts an index into its corresponding inhabitant.

default fromFinite :: (Generic a, GFinitary (Rep a), Cardinality a ~ GCardinality (Rep a)) => Finite (Cardinality a) -> a Source #

toFinite :: a -> Finite (Cardinality a) Source #

Converts an inhabitant to its corresponding index.

default toFinite :: (Generic a, GFinitary (Rep a), Cardinality a ~ GCardinality (Rep a)) => a -> Finite (Cardinality a) Source #

start :: 1 <= Cardinality a => a Source #

The first inhabitant, by index, assuming a has any inhabitants.

end :: 1 <= Cardinality a => a Source #

The last inhabitant, by index, assuming a has any inhabitants.

previous :: Alternative f => a -> f a Source #

previous x gives the inhabitant whose index precedes the index of x, or empty if no such index exists.

previousSkipping :: Alternative f => Finite (Cardinality a) -> a -> f a Source #

previousSkipping i x 'skips back' i index values from the index of x, then gives the inhabitant whose index precedes the result, or empty if no such index exists.

next :: Alternative f => a -> f a Source #

next x gives the inhabitant whose index follows the index of x, or empty if no such index exists.

nextSkipping :: Alternative f => Finite (Cardinality a) -> a -> f a Source #

nextSkipping i x 'skips forward' i index values from the index of x, then gives the inhabitant whose index follows the result, or empty if no such index exists.

enumerateFrom :: a -> [a] Source #

enumerateFrom x gives a list of inhabitants, starting with x, followed by all other values whose indexes follow x, in index order.

enumerateFromThen :: a -> a -> [a] Source #

Like enumerateFrom, except in steps of toFinite y - toFinite x.

enumerateFromTo :: a -> a -> [a] Source #

enumerateFromTo x y gives a list of inhabitants, starting with x, ending with y, and containing all other values whose indices lie between those of x and y. The list is in index order.

enumerateFromThenTo :: a -> a -> a -> [a] Source #

Like enumerateFromTo, except in steps of toFinite y - toFinite x.

#### Instances

Instances details
 Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Bool -> f Bool Source #next :: Alternative f => Bool -> f Bool Source #nextSkipping :: Alternative f => Finite (Cardinality Bool) -> Bool -> f Bool Source #enumerateFrom :: Bool -> [Bool] Source #enumerateFromThen :: Bool -> Bool -> [Bool] Source #enumerateFromTo :: Bool -> Bool -> [Bool] Source #enumerateFromThenTo :: Bool -> Bool -> Bool -> [Bool] Source # Source # Char has one inhabitant per Unicode code point. Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Char -> f Char Source #next :: Alternative f => Char -> f Char Source #nextSkipping :: Alternative f => Finite (Cardinality Char) -> Char -> f Char Source #enumerateFrom :: Char -> [Char] Source #enumerateFromThen :: Char -> Char -> [Char] Source #enumerateFromTo :: Char -> Char -> [Char] Source #enumerateFromThenTo :: Char -> Char -> Char -> [Char] Source # Source # Int has a finite number of inhabitants, varying by platform. This instance will determine this when the library is built. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality Int :: Nat Source # Methodsprevious :: Alternative f => Int -> f Int Source #previousSkipping :: Alternative f => Finite (Cardinality Int) -> Int -> f Int Source #next :: Alternative f => Int -> f Int Source #nextSkipping :: Alternative f => Finite (Cardinality Int) -> Int -> f Int Source #enumerateFrom :: Int -> [Int] Source #enumerateFromThen :: Int -> Int -> [Int] Source #enumerateFromTo :: Int -> Int -> [Int] Source #enumerateFromThenTo :: Int -> Int -> Int -> [Int] Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Int8 -> f Int8 Source #next :: Alternative f => Int8 -> f Int8 Source #nextSkipping :: Alternative f => Finite (Cardinality Int8) -> Int8 -> f Int8 Source #enumerateFrom :: Int8 -> [Int8] Source #enumerateFromThen :: Int8 -> Int8 -> [Int8] Source #enumerateFromTo :: Int8 -> Int8 -> [Int8] Source #enumerateFromThenTo :: Int8 -> Int8 -> Int8 -> [Int8] Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Int16 -> f Int16 Source #next :: Alternative f => Int16 -> f Int16 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Int32 -> f Int32 Source #next :: Alternative f => Int32 -> f Int32 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Int64 -> f Int64 Source #next :: Alternative f => Int64 -> f Int64 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsnext :: Alternative f => Ordering -> f Ordering Source # Source # Word has a finite number of inhabitants, varying by platform. This instance will determine this when the library is built. Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Word -> f Word Source #next :: Alternative f => Word -> f Word Source #nextSkipping :: Alternative f => Finite (Cardinality Word) -> Word -> f Word Source #enumerateFrom :: Word -> [Word] Source #enumerateFromThen :: Word -> Word -> [Word] Source #enumerateFromTo :: Word -> Word -> [Word] Source #enumerateFromThenTo :: Word -> Word -> Word -> [Word] Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Word8 -> f Word8 Source #next :: Alternative f => Word8 -> f Word8 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Word16 -> f Word16 Source #next :: Alternative f => Word16 -> f Word16 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Word32 -> f Word32 Source #next :: Alternative f => Word32 -> f Word32 Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Word64 -> f Word64 Source #next :: Alternative f => Word64 -> f Word64 Source # Finitary () Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality () :: Nat Source # MethodsfromFinite :: Finite (Cardinality ()) -> () Source #toFinite :: () -> Finite (Cardinality ()) Source #start :: () Source #end :: () Source #previous :: Alternative f => () -> f () Source #previousSkipping :: Alternative f => Finite (Cardinality ()) -> () -> f () Source #next :: Alternative f => () -> f () Source #nextSkipping :: Alternative f => Finite (Cardinality ()) -> () -> f () Source #enumerateFrom :: () -> [()] Source #enumerateFromThen :: () -> () -> [()] Source #enumerateFromTo :: () -> () -> [()] Source #enumerateFromThenTo :: () -> () -> () -> [()] Source # Source # Instance detailsDefined in Data.Finitary Associated Types Methodsprevious :: Alternative f => Void -> f Void Source #next :: Alternative f => Void -> f Void Source #nextSkipping :: Alternative f => Finite (Cardinality Void) -> Void -> f Void Source #enumerateFrom :: Void -> [Void] Source #enumerateFromThen :: Void -> Void -> [Void] Source #enumerateFromTo :: Void -> Void -> [Void] Source #enumerateFromThenTo :: Void -> Void -> Void -> [Void] Source # Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality All :: Nat Source # Methodsprevious :: Alternative f => All -> f All Source #previousSkipping :: Alternative f => Finite (Cardinality All) -> All -> f All Source #next :: Alternative f => All -> f All Source #nextSkipping :: Alternative f => Finite (Cardinality All) -> All -> f All Source #enumerateFrom :: All -> [All] Source #enumerateFromThen :: All -> All -> [All] Source #enumerateFromTo :: All -> All -> [All] Source #enumerateFromThenTo :: All -> All -> All -> [All] Source # Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality Any :: Nat Source # Methodsprevious :: Alternative f => Any -> f Any Source #previousSkipping :: Alternative f => Finite (Cardinality Any) -> Any -> f Any Source #next :: Alternative f => Any -> f Any Source #nextSkipping :: Alternative f => Finite (Cardinality Any) -> Any -> f Any Source #enumerateFrom :: Any -> [Any] Source #enumerateFromThen :: Any -> Any -> [Any] Source #enumerateFromTo :: Any -> Any -> [Any] Source #enumerateFromThenTo :: Any -> Any -> Any -> [Any] Source # Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality Bit :: Nat Source # Methodsprevious :: Alternative f => Bit -> f Bit Source #previousSkipping :: Alternative f => Finite (Cardinality Bit) -> Bit -> f Bit Source #next :: Alternative f => Bit -> f Bit Source #nextSkipping :: Alternative f => Finite (Cardinality Bit) -> Bit -> f Bit Source #enumerateFrom :: Bit -> [Bit] Source #enumerateFromThen :: Bit -> Bit -> [Bit] Source #enumerateFromTo :: Bit -> Bit -> [Bit] Source #enumerateFromThenTo :: Bit -> Bit -> Bit -> [Bit] Source # Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality Bit :: Nat Source # Methodsprevious :: Alternative f => Bit -> f Bit Source #previousSkipping :: Alternative f => Finite (Cardinality Bit) -> Bit -> f Bit Source #next :: Alternative f => Bit -> f Bit Source #nextSkipping :: Alternative f => Finite (Cardinality Bit) -> Bit -> f Bit Source #enumerateFrom :: Bit -> [Bit] Source #enumerateFromThen :: Bit -> Bit -> [Bit] Source #enumerateFromTo :: Bit -> Bit -> [Bit] Source #enumerateFromThenTo :: Bit -> Bit -> Bit -> [Bit] Source # Finitary a => Finitary (Maybe a) Source # Maybe a introduces one additional inhabitant (namely, Nothing) to a. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Maybe a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Maybe a)) -> Maybe a Source #toFinite :: Maybe a -> Finite (Cardinality (Maybe a)) Source #previous :: Alternative f => Maybe a -> f (Maybe a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Maybe a)) -> Maybe a -> f (Maybe a) Source #next :: Alternative f => Maybe a -> f (Maybe a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Maybe a)) -> Maybe a -> f (Maybe a) Source #enumerateFrom :: Maybe a -> [Maybe a] Source #enumerateFromThen :: Maybe a -> Maybe a -> [Maybe a] Source #enumerateFromTo :: Maybe a -> Maybe a -> [Maybe a] Source #enumerateFromThenTo :: Maybe a -> Maybe a -> Maybe a -> [Maybe a] Source # Finitary a => Finitary (Min a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Min a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Min a)) -> Min a Source #toFinite :: Min a -> Finite (Cardinality (Min a)) Source #previous :: Alternative f => Min a -> f (Min a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Min a)) -> Min a -> f (Min a) Source #next :: Alternative f => Min a -> f (Min a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Min a)) -> Min a -> f (Min a) Source #enumerateFrom :: Min a -> [Min a] Source #enumerateFromThen :: Min a -> Min a -> [Min a] Source #enumerateFromTo :: Min a -> Min a -> [Min a] Source #enumerateFromThenTo :: Min a -> Min a -> Min a -> [Min a] Source # Finitary a => Finitary (Max a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Max a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Max a)) -> Max a Source #toFinite :: Max a -> Finite (Cardinality (Max a)) Source #previous :: Alternative f => Max a -> f (Max a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Max a)) -> Max a -> f (Max a) Source #next :: Alternative f => Max a -> f (Max a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Max a)) -> Max a -> f (Max a) Source #enumerateFrom :: Max a -> [Max a] Source #enumerateFromThen :: Max a -> Max a -> [Max a] Source #enumerateFromTo :: Max a -> Max a -> [Max a] Source #enumerateFromThenTo :: Max a -> Max a -> Max a -> [Max a] Source # Finitary a => Finitary (First a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (First a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (First a)) -> First a Source #toFinite :: First a -> Finite (Cardinality (First a)) Source #previous :: Alternative f => First a -> f (First a) Source #previousSkipping :: Alternative f => Finite (Cardinality (First a)) -> First a -> f (First a) Source #next :: Alternative f => First a -> f (First a) Source #nextSkipping :: Alternative f => Finite (Cardinality (First a)) -> First a -> f (First a) Source #enumerateFrom :: First a -> [First a] Source #enumerateFromThen :: First a -> First a -> [First a] Source #enumerateFromTo :: First a -> First a -> [First a] Source #enumerateFromThenTo :: First a -> First a -> First a -> [First a] Source # Finitary a => Finitary (Last a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Last a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Last a)) -> Last a Source #toFinite :: Last a -> Finite (Cardinality (Last a)) Source #previous :: Alternative f => Last a -> f (Last a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Last a)) -> Last a -> f (Last a) Source #next :: Alternative f => Last a -> f (Last a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Last a)) -> Last a -> f (Last a) Source #enumerateFrom :: Last a -> [Last a] Source #enumerateFromThen :: Last a -> Last a -> [Last a] Source #enumerateFromTo :: Last a -> Last a -> [Last a] Source #enumerateFromThenTo :: Last a -> Last a -> Last a -> [Last a] Source # Finitary a => Finitary (Identity a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Identity a) :: Nat Source # Methodsprevious :: Alternative f => Identity a -> f (Identity a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Identity a)) -> Identity a -> f (Identity a) Source #next :: Alternative f => Identity a -> f (Identity a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Identity a)) -> Identity a -> f (Identity a) Source #enumerateFrom :: Identity a -> [Identity a] Source #enumerateFromThen :: Identity a -> Identity a -> [Identity a] Source #enumerateFromTo :: Identity a -> Identity a -> [Identity a] Source #enumerateFromThenTo :: Identity a -> Identity a -> Identity a -> [Identity a] Source # Finitary a => Finitary (Dual a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Dual a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Dual a)) -> Dual a Source #toFinite :: Dual a -> Finite (Cardinality (Dual a)) Source #previous :: Alternative f => Dual a -> f (Dual a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Dual a)) -> Dual a -> f (Dual a) Source #next :: Alternative f => Dual a -> f (Dual a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Dual a)) -> Dual a -> f (Dual a) Source #enumerateFrom :: Dual a -> [Dual a] Source #enumerateFromThen :: Dual a -> Dual a -> [Dual a] Source #enumerateFromTo :: Dual a -> Dual a -> [Dual a] Source #enumerateFromThenTo :: Dual a -> Dual a -> Dual a -> [Dual a] Source # Finitary a => Finitary (Sum a) Source # For any newtype-esque thing over a type with a Finitary instance, we can just 'inherit' the behaviour of a. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Sum a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Sum a)) -> Sum a Source #toFinite :: Sum a -> Finite (Cardinality (Sum a)) Source #previous :: Alternative f => Sum a -> f (Sum a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Sum a)) -> Sum a -> f (Sum a) Source #next :: Alternative f => Sum a -> f (Sum a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Sum a)) -> Sum a -> f (Sum a) Source #enumerateFrom :: Sum a -> [Sum a] Source #enumerateFromThen :: Sum a -> Sum a -> [Sum a] Source #enumerateFromTo :: Sum a -> Sum a -> [Sum a] Source #enumerateFromThenTo :: Sum a -> Sum a -> Sum a -> [Sum a] Source # Finitary a => Finitary (Product a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Product a) :: Nat Source # Methodsprevious :: Alternative f => Product a -> f (Product a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Product a)) -> Product a -> f (Product a) Source #next :: Alternative f => Product a -> f (Product a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Product a)) -> Product a -> f (Product a) Source #enumerateFrom :: Product a -> [Product a] Source #enumerateFromThen :: Product a -> Product a -> [Product a] Source #enumerateFromTo :: Product a -> Product a -> [Product a] Source #enumerateFromThenTo :: Product a -> Product a -> Product a -> [Product a] Source # Finitary a => Finitary (Down a) Source # Despite the newtype-esque nature of Down, due to the requirement that fromFinite is order-preserving, the instance for Down a reverses the indexing. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Down a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Down a)) -> Down a Source #toFinite :: Down a -> Finite (Cardinality (Down a)) Source #previous :: Alternative f => Down a -> f (Down a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Down a)) -> Down a -> f (Down a) Source #next :: Alternative f => Down a -> f (Down a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Down a)) -> Down a -> f (Down a) Source #enumerateFrom :: Down a -> [Down a] Source #enumerateFromThen :: Down a -> Down a -> [Down a] Source #enumerateFromTo :: Down a -> Down a -> [Down a] Source #enumerateFromThenTo :: Down a -> Down a -> Down a -> [Down a] Source # KnownNat n => Finitary (Finite n) Source # Since any type is isomorphic to itself, it follows that a 'valid' Finite n (meaning that n is a KnownNat) has finite cardinality. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Finite n) :: Nat Source # MethodstoFinite :: Finite n -> Finite (Cardinality (Finite n)) Source #previous :: Alternative f => Finite n -> f (Finite n) Source #previousSkipping :: Alternative f => Finite (Cardinality (Finite n)) -> Finite n -> f (Finite n) Source #next :: Alternative f => Finite n -> f (Finite n) Source #nextSkipping :: Alternative f => Finite (Cardinality (Finite n)) -> Finite n -> f (Finite n) Source #enumerateFrom :: Finite n -> [Finite n] Source #enumerateFromThen :: Finite n -> Finite n -> [Finite n] Source #enumerateFromTo :: Finite n -> Finite n -> [Finite n] Source #enumerateFromThenTo :: Finite n -> Finite n -> Finite n -> [Finite n] Source # (Finitary a, Finitary b) => Finitary (Either a b) Source # The sum of two finite types will also be finite, with a cardinality equal to the sum of their cardinalities. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Either a b) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Either a b)) -> Either a b Source #toFinite :: Either a b -> Finite (Cardinality (Either a b)) Source #start :: Either a b Source #end :: Either a b Source #previous :: Alternative f => Either a b -> f (Either a b) Source #previousSkipping :: Alternative f => Finite (Cardinality (Either a b)) -> Either a b -> f (Either a b) Source #next :: Alternative f => Either a b -> f (Either a b) Source #nextSkipping :: Alternative f => Finite (Cardinality (Either a b)) -> Either a b -> f (Either a b) Source #enumerateFrom :: Either a b -> [Either a b] Source #enumerateFromThen :: Either a b -> Either a b -> [Either a b] Source #enumerateFromTo :: Either a b -> Either a b -> [Either a b] Source #enumerateFromThenTo :: Either a b -> Either a b -> Either a b -> [Either a b] Source # (Finitary a, Finitary b) => Finitary (a, b) Source # The product of two finite types will also be finite, with a cardinality equal to the product of their cardinalities. Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (a, b) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (a, b)) -> (a, b) Source #toFinite :: (a, b) -> Finite (Cardinality (a, b)) Source #start :: (a, b) Source #end :: (a, b) Source #previous :: Alternative f => (a, b) -> f (a, b) Source #previousSkipping :: Alternative f => Finite (Cardinality (a, b)) -> (a, b) -> f (a, b) Source #next :: Alternative f => (a, b) -> f (a, b) Source #nextSkipping :: Alternative f => Finite (Cardinality (a, b)) -> (a, b) -> f (a, b) Source #enumerateFrom :: (a, b) -> [(a, b)] Source #enumerateFromThen :: (a, b) -> (a, b) -> [(a, b)] Source #enumerateFromTo :: (a, b) -> (a, b) -> [(a, b)] Source #enumerateFromThenTo :: (a, b) -> (a, b) -> (a, b) -> [(a, b)] Source # Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Proxy a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Proxy a)) -> Proxy a Source #toFinite :: Proxy a -> Finite (Cardinality (Proxy a)) Source #previous :: Alternative f => Proxy a -> f (Proxy a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Proxy a)) -> Proxy a -> f (Proxy a) Source #next :: Alternative f => Proxy a -> f (Proxy a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Proxy a)) -> Proxy a -> f (Proxy a) Source #enumerateFrom :: Proxy a -> [Proxy a] Source #enumerateFromThen :: Proxy a -> Proxy a -> [Proxy a] Source #enumerateFromTo :: Proxy a -> Proxy a -> [Proxy a] Source #enumerateFromThenTo :: Proxy a -> Proxy a -> Proxy a -> [Proxy a] Source # (Finitary a, Unbox a, KnownNat n) => Finitary (Vector n a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Vector n a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Vector n a)) -> Vector n a Source #toFinite :: Vector n a -> Finite (Cardinality (Vector n a)) Source #start :: Vector n a Source #end :: Vector n a Source #previous :: Alternative f => Vector n a -> f (Vector n a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #next :: Alternative f => Vector n a -> f (Vector n a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #enumerateFrom :: Vector n a -> [Vector n a] Source #enumerateFromThen :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromTo :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromThenTo :: Vector n a -> Vector n a -> Vector n a -> [Vector n a] Source # (Finitary a, Storable a, KnownNat n) => Finitary (Vector n a) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Vector n a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Vector n a)) -> Vector n a Source #toFinite :: Vector n a -> Finite (Cardinality (Vector n a)) Source #start :: Vector n a Source #end :: Vector n a Source #previous :: Alternative f => Vector n a -> f (Vector n a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #next :: Alternative f => Vector n a -> f (Vector n a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #enumerateFrom :: Vector n a -> [Vector n a] Source #enumerateFromThen :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromTo :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromThenTo :: Vector n a -> Vector n a -> Vector n a -> [Vector n a] Source # (Finitary a, KnownNat n) => Finitary (Vector n a) Source # A fixed-length vector over a type a with an instance of Finitary can be thought of as a fixed-length word over an alphabet of size Cardinality a. Since there are only finitely-many of these, we can index them in lex order, with the ordering determined by the Finitary a instance (thus, the 'first' such Vector is the one where each element is start :: a, and the 'last' is the one where each element is end :: a). Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Vector n a) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Vector n a)) -> Vector n a Source #toFinite :: Vector n a -> Finite (Cardinality (Vector n a)) Source #start :: Vector n a Source #end :: Vector n a Source #previous :: Alternative f => Vector n a -> f (Vector n a) Source #previousSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #next :: Alternative f => Vector n a -> f (Vector n a) Source #nextSkipping :: Alternative f => Finite (Cardinality (Vector n a)) -> Vector n a -> f (Vector n a) Source #enumerateFrom :: Vector n a -> [Vector n a] Source #enumerateFromThen :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromTo :: Vector n a -> Vector n a -> [Vector n a] Source #enumerateFromThenTo :: Vector n a -> Vector n a -> Vector n a -> [Vector n a] Source # (Finitary a, Finitary b, Finitary c) => Finitary (a, b, c) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (a, b, c) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (a, b, c)) -> (a, b, c) Source #toFinite :: (a, b, c) -> Finite (Cardinality (a, b, c)) Source #start :: (a, b, c) Source #end :: (a, b, c) Source #previous :: Alternative f => (a, b, c) -> f (a, b, c) Source #previousSkipping :: Alternative f => Finite (Cardinality (a, b, c)) -> (a, b, c) -> f (a, b, c) Source #next :: Alternative f => (a, b, c) -> f (a, b, c) Source #nextSkipping :: Alternative f => Finite (Cardinality (a, b, c)) -> (a, b, c) -> f (a, b, c) Source #enumerateFrom :: (a, b, c) -> [(a, b, c)] Source #enumerateFromThen :: (a, b, c) -> (a, b, c) -> [(a, b, c)] Source #enumerateFromTo :: (a, b, c) -> (a, b, c) -> [(a, b, c)] Source #enumerateFromThenTo :: (a, b, c) -> (a, b, c) -> (a, b, c) -> [(a, b, c)] Source # Finitary a => Finitary (Const a b) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (Const a b) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (Const a b)) -> Const a b Source #toFinite :: Const a b -> Finite (Cardinality (Const a b)) Source #start :: Const a b Source #end :: Const a b Source #previous :: Alternative f => Const a b -> f (Const a b) Source #previousSkipping :: Alternative f => Finite (Cardinality (Const a b)) -> Const a b -> f (Const a b) Source #next :: Alternative f => Const a b -> f (Const a b) Source #nextSkipping :: Alternative f => Finite (Cardinality (Const a b)) -> Const a b -> f (Const a b) Source #enumerateFrom :: Const a b -> [Const a b] Source #enumerateFromThen :: Const a b -> Const a b -> [Const a b] Source #enumerateFromTo :: Const a b -> Const a b -> [Const a b] Source #enumerateFromThenTo :: Const a b -> Const a b -> Const a b -> [Const a b] Source # (Finitary a, Finitary b, Finitary c, Finitary d) => Finitary (a, b, c, d) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (a, b, c, d) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (a, b, c, d)) -> (a, b, c, d) Source #toFinite :: (a, b, c, d) -> Finite (Cardinality (a, b, c, d)) Source #start :: (a, b, c, d) Source #end :: (a, b, c, d) Source #previous :: Alternative f => (a, b, c, d) -> f (a, b, c, d) Source #previousSkipping :: Alternative f => Finite (Cardinality (a, b, c, d)) -> (a, b, c, d) -> f (a, b, c, d) Source #next :: Alternative f => (a, b, c, d) -> f (a, b, c, d) Source #nextSkipping :: Alternative f => Finite (Cardinality (a, b, c, d)) -> (a, b, c, d) -> f (a, b, c, d) Source #enumerateFrom :: (a, b, c, d) -> [(a, b, c, d)] Source #enumerateFromThen :: (a, b, c, d) -> (a, b, c, d) -> [(a, b, c, d)] Source #enumerateFromTo :: (a, b, c, d) -> (a, b, c, d) -> [(a, b, c, d)] Source #enumerateFromThenTo :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) -> [(a, b, c, d)] Source # (Finitary a, Finitary b, Finitary c, Finitary d, Finitary e) => Finitary (a, b, c, d, e) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (a, b, c, d, e) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (a, b, c, d, e)) -> (a, b, c, d, e) Source #toFinite :: (a, b, c, d, e) -> Finite (Cardinality (a, b, c, d, e)) Source #start :: (a, b, c, d, e) Source #end :: (a, b, c, d, e) Source #previous :: Alternative f => (a, b, c, d, e) -> f (a, b, c, d, e) Source #previousSkipping :: Alternative f => Finite (Cardinality (a, b, c, d, e)) -> (a, b, c, d, e) -> f (a, b, c, d, e) Source #next :: Alternative f => (a, b, c, d, e) -> f (a, b, c, d, e) Source #nextSkipping :: Alternative f => Finite (Cardinality (a, b, c, d, e)) -> (a, b, c, d, e) -> f (a, b, c, d, e) Source #enumerateFrom :: (a, b, c, d, e) -> [(a, b, c, d, e)] Source #enumerateFromThen :: (a, b, c, d, e) -> (a, b, c, d, e) -> [(a, b, c, d, e)] Source #enumerateFromTo :: (a, b, c, d, e) -> (a, b, c, d, e) -> [(a, b, c, d, e)] Source #enumerateFromThenTo :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) -> [(a, b, c, d, e)] Source # (Finitary a, Finitary b, Finitary c, Finitary d, Finitary e, Finitary f) => Finitary (a, b, c, d, e, f) Source # Instance detailsDefined in Data.Finitary Associated Typestype Cardinality (a, b, c, d, e, f) :: Nat Source # MethodsfromFinite :: Finite (Cardinality (a, b, c, d, e, f)) -> (a, b, c, d, e, f) Source #toFinite :: (a, b, c, d, e, f) -> Finite (Cardinality (a, b, c, d, e, f)) Source #start :: (a, b, c, d, e, f) Source #end :: (a, b, c, d, e, f) Source #previous :: Alternative f0 => (a, b, c, d, e, f) -> f0 (a, b, c, d, e, f) Source #previousSkipping :: Alternative f0 => Finite (Cardinality (a, b, c, d, e, f)) -> (a, b, c, d, e, f) -> f0 (a, b, c, d, e, f) Source #next :: Alternative f0 => (a, b, c, d, e, f) -> f0 (a, b, c, d, e, f) Source #nextSkipping :: Alternative f0 => Finite (Cardinality (a, b, c, d, e, f)) -> (a, b, c, d, e, f) -> f0 (a, b, c, d, e, f) Source #enumerateFrom :: (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source #enumerateFromThen :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source #enumerateFromTo :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source #enumerateFromThenTo :: (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> (a, b, c, d, e, f) -> [(a, b, c, d, e, f)] Source #