universe-base-1.1.3: A class for finite and recursively enumerable types.
Safe Haskell Safe
Language Haskell2010

Data.Universe.Helpers

Synopsis

Documentation

This module is for functions that are useful for writing instances, but not necessarily for using them (and hence are not exported by the main module to avoid cluttering up the namespace).

Building lists

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

For many types, the universe should be [minBound .. maxBound] ; universeDef makes it easy to make such types an instance of Universe via the snippet

instance Universe Foo where universe = universeDef

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

Fair n-way interleaving: given a finite number of (possibly infinite) lists, produce a single list such that whenever v has finite index in one of the input lists, v also has finite index in the output list. No list's elements occur more frequently (on average) than another's.

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

Unfair n-way interleaving: given a possibly infinite number of (possibly infinite) lists, produce a single list such that whenever v has finite index in an input list at finite index, v also has finite index in the output list. Elements from lists at lower index occur more frequently, but not exponentially so.

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

Like diagonal , but expose a tiny bit more (non-semantic) information: if you lay out the input list in two dimensions, each list in the result will be one of the diagonals of the input. In particular, each element of the output will be a list whose elements are each from a distinct input list.

(+++) :: [a] -> [a] -> [a] Source #

Fair 2-way interleaving.

cartesianProduct :: (a -> b -> c) -> [a] -> [b] -> [c] Source #

Slightly unfair 2-way Cartesian product: given two (possibly infinite) lists, produce a single list such that whenever v and w have finite indices in the input lists, (v,w) has finite index in the output list. Lower indices occur as the fst part of the tuple more frequently, but not exponentially so.

(+*+) :: [a] -> [b] -> [(a, b)] Source #

(<+*+>) :: [a -> b] -> [a] -> [b] Source #

A +*+ with application.

cartesianProduct ($)

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

Slightly unfair n-way Cartesian product: given a finite number of (possibly infinite) lists, produce a single list such that whenever vi has finite index in list i for each i, [v1, ..., vn] has finite index in the output list.

Building cardinalities

These functions are handy for inheriting the definition of cardinality in a newtype instance. For example, one might write

newtype Foo = Foo Bar
instance Finite Foo where cardinality = retagWith Foo cardinality

retag :: forall k1 k2 (s :: k1) b (t :: k2). Tagged s b -> Tagged t b Source #

Some times you need to change the tag you have lying around. Idiomatic usage is to make a new combinator for the relationship between the tags that you want to enforce, and define that combinator using retag .

data Succ n
retagSucc :: Tagged n a -> Tagged (Succ n) a
retagSucc = retag

newtype Tagged (s :: k) b Source #

A Tagged s b value is a value b with an attached phantom type s . This can be used in place of the more traditional but less safe idiom of passing in an undefined value with the type, because unlike an (s -> b) , a Tagged s b can't try to use the argument s as a real value.

Moreover, you don't have to rely on the compiler to inline away the extra argument, because the newtype is "free"

Tagged has kind k -> * -> * if the compiler supports PolyKinds , therefore there is an extra k showing in the instance haddocks that may cause confusion.

Constructors

Tagged

Fields

Instances

Instances details
Bitraversable ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Tagged a b -> f ( Tagged c d) Source #

Bifoldable ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

bifold :: Monoid m => Tagged m m -> m Source #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> Tagged a b -> m Source #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> Tagged a b -> c Source #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> Tagged a b -> c Source #

Bifunctor ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

bimap :: (a -> b) -> (c -> d) -> Tagged a c -> Tagged b d Source #

first :: (a -> b) -> Tagged a c -> Tagged b c Source #

second :: (b -> c) -> Tagged a b -> Tagged a c Source #

Eq2 ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

liftEq2 :: (a -> b -> Bool ) -> (c -> d -> Bool ) -> Tagged a c -> Tagged b d -> Bool Source #

Ord2 ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

liftCompare2 :: (a -> b -> Ordering ) -> (c -> d -> Ordering ) -> Tagged a c -> Tagged b d -> Ordering Source #

Read2 ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Show2 ( Tagged :: Type -> Type -> Type )
Instance details

Defined in Data.Tagged

Methods

liftShowsPrec2 :: ( Int -> a -> ShowS ) -> ([a] -> ShowS ) -> ( Int -> b -> ShowS ) -> ([b] -> ShowS ) -> Int -> Tagged a b -> ShowS Source #

liftShowList2 :: ( Int -> a -> ShowS ) -> ([a] -> ShowS ) -> ( Int -> b -> ShowS ) -> ([b] -> ShowS ) -> [ Tagged a b] -> ShowS Source #

Generic1 ( Tagged s :: Type -> Type )
Instance details

Defined in Data.Tagged

Associated Types

type Rep1 ( Tagged s) :: k -> Type Source #

Methods

from1 :: forall (a :: k). Tagged s a -> Rep1 ( Tagged s) a Source #

to1 :: forall (a :: k). Rep1 ( Tagged s) a -> Tagged s a Source #

Monad ( Tagged s)
Instance details

Defined in Data.Tagged

Functor ( Tagged s)
Instance details

Defined in Data.Tagged

Methods

fmap :: (a -> b) -> Tagged s a -> Tagged s b Source #

(<$) :: a -> Tagged s b -> Tagged s a Source #

Applicative ( Tagged s)
Instance details

Defined in Data.Tagged

Foldable ( Tagged s)
Instance details

Defined in Data.Tagged

Traversable ( Tagged s)
Instance details

Defined in Data.Tagged

Eq1 ( Tagged s)
Instance details

Defined in Data.Tagged

Methods

liftEq :: (a -> b -> Bool ) -> Tagged s a -> Tagged s b -> Bool Source #

Ord1 ( Tagged s)
Instance details

Defined in Data.Tagged

Read1 ( Tagged s)
Instance details

Defined in Data.Tagged

Show1 ( Tagged s)
Instance details

Defined in Data.Tagged

Bounded b => Bounded ( Tagged s b)
Instance details

Defined in Data.Tagged

Enum a => Enum ( Tagged s a)
Instance details

Defined in Data.Tagged

Eq b => Eq ( Tagged s b)
Instance details

Defined in Data.Tagged

Floating a => Floating ( Tagged s a)
Instance details

Defined in Data.Tagged

Fractional a => Fractional ( Tagged s a)
Instance details

Defined in Data.Tagged

Integral a => Integral ( Tagged s a)
Instance details

Defined in Data.Tagged

( Data s, Data b) => Data ( Tagged s b)
Instance details

Defined in Data.Tagged

Methods

gfoldl :: ( forall d b0. Data d => c (d -> b0) -> d -> c b0) -> ( forall g. g -> c g) -> Tagged s b -> c ( Tagged s b) Source #

gunfold :: ( forall b0 r. Data b0 => c (b0 -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( Tagged s b) Source #

toConstr :: Tagged s b -> Constr Source #

dataTypeOf :: Tagged s b -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( Tagged s b)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( Tagged s b)) Source #

gmapT :: ( forall b0. Data b0 => b0 -> b0) -> Tagged s b -> Tagged s b Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> Tagged s b -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> Tagged s b -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> Tagged s b -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> Tagged s b -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> Tagged s b -> m ( Tagged s b) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> Tagged s b -> m ( Tagged s b) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> Tagged s b -> m ( Tagged s b) Source #

Num a => Num ( Tagged s a)
Instance details

Defined in Data.Tagged

Ord b => Ord ( Tagged s b)
Instance details

Defined in Data.Tagged

Read b => Read ( Tagged s b)
Instance details

Defined in Data.Tagged

Real a => Real ( Tagged s a)
Instance details

Defined in Data.Tagged

RealFloat a => RealFloat ( Tagged s a)
Instance details

Defined in Data.Tagged

RealFrac a => RealFrac ( Tagged s a)
Instance details

Defined in Data.Tagged

Show b => Show ( Tagged s b)
Instance details

Defined in Data.Tagged

Ix b => Ix ( Tagged s b)
Instance details

Defined in Data.Tagged

IsString a => IsString ( Tagged s a)
Instance details

Defined in Data.Tagged

Generic ( Tagged s b)
Instance details

Defined in Data.Tagged

Associated Types

type Rep ( Tagged s b) :: Type -> Type Source #

Semigroup a => Semigroup ( Tagged s a)
Instance details

Defined in Data.Tagged

( Semigroup a, Monoid a) => Monoid ( Tagged s a)
Instance details

Defined in Data.Tagged

Storable a => Storable ( Tagged s a)
Instance details

Defined in Data.Tagged

Bits a => Bits ( Tagged s a)
Instance details

Defined in Data.Tagged

FiniteBits a => FiniteBits ( Tagged s a)
Instance details

Defined in Data.Tagged

NFData b => NFData ( Tagged s b)
Instance details

Defined in Data.Tagged

Methods

rnf :: Tagged s b -> () Source #

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

Defined in Data.Universe.Class

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

Defined in Data.Universe.Class

type Rep1 ( Tagged s :: Type -> Type )
Instance details

Defined in Data.Tagged

type Rep1 ( Tagged s :: Type -> Type ) = D1 (' MetaData "Tagged" "Data.Tagged" "tagged-0.8.7-Hh8SrsJ8Ofo2TZerdJ0cCc" ' True ) ( C1 (' MetaCons "Tagged" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unTagged") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) Par1 ))
type Rep ( Tagged s b)
Instance details

Defined in Data.Tagged

type Rep ( Tagged s b) = D1 (' MetaData "Tagged" "Data.Tagged" "tagged-0.8.7-Hh8SrsJ8Ofo2TZerdJ0cCc" ' True ) ( C1 (' MetaCons "Tagged" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "unTagged") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 b)))

data Natural Source #

Type representing arbitrary-precision non-negative integers.

>>> 2^100 :: Natural
1267650600228229401496703205376

Operations whose result would be negative throw ( Underflow :: ArithException ) ,

>>> -1 :: Natural
*** Exception: arithmetic underflow

Since: base-4.8.0.0

Instances

Instances details
Enum Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Enum

Eq Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Natural

Integral Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Real

Num Natural

Note that Natural 's Num instance isn't a ring: no element but 0 has an additive inverse. It is a semiring though.

Since: base-4.8.0.0

Instance details

Defined in GHC.Num

Ord Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Natural

Read Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Read

Real Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Real

Show Natural

Since: base-4.8.0.0

Instance details

Defined in GHC.Show

Hashable Natural
Instance details

Defined in Data.Hashable.Class

Universe Natural Source #
Instance details

Defined in Data.Universe.Class

Lift Natural
Instance details

Defined in Language.Haskell.TH.Syntax

Debugging

These functions exist primarily as a specification to test against.

unfairCartesianProduct :: (a -> b -> c) -> [a] -> [b] -> [c] Source #

Very unfair 2-way Cartesian product: same guarantee as the slightly unfair one, except that lower indices may occur as the fst part of the tuple exponentially more frequently.

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

Very unfair n-way Cartesian product: same guarantee as the slightly unfair one, but not as good in the same sense that the very unfair 2-way product is worse than the slightly unfair 2-way product.