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:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27
Moduleuniverse-base-1.1.4Haskell2010
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).
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 = universeDefFair 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.
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.
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.
Fair 2-way interleaving.
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.
cartesianProduct (,)A +*+ with application.
cartesianProduct ($)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.
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 cardinalityA 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.
Generic1 (Tagged s)Defined in tagged-0.8.9 · Data.TaggedBifoldable TaggedDefined in tagged-0.8.9 · Data.TaggedBifoldable1 TaggedDefined in tagged-0.8.9 · Data.TaggedBifunctor TaggedDefined in tagged-0.8.9 · Data.TaggedBitraversable TaggedDefined in tagged-0.8.9 · Data.TaggedEq2 TaggedDefined in tagged-0.8.9 · Data.TaggedOrd2 TaggedDefined in tagged-0.8.9 · Data.TaggedRead2 TaggedDefined in tagged-0.8.9 · Data.TaggedShow2 TaggedDefined in tagged-0.8.9 · Data.TaggedMonad (Tagged s)Defined in tagged-0.8.9 · Data.TaggedFunctor (Tagged s)Defined in tagged-0.8.9 · Data.TaggedApplicative (Tagged s)Defined in tagged-0.8.9 · Data.TaggedFoldable (Tagged s)Defined in tagged-0.8.9 · Data.TaggedTraversable (Tagged s)Defined in tagged-0.8.9 · Data.TaggedFoldable1 (Tagged a)Defined in tagged-0.8.9 · Data.TaggedEq1 (Tagged s)Defined in tagged-0.8.9 · Data.TaggedOrd1 (Tagged s)Defined in tagged-0.8.9 · Data.TaggedRead1 (Tagged s)Defined in tagged-0.8.9 · Data.TaggedShow1 (Tagged s)Defined in tagged-0.8.9 · Data.TaggedBounded b => Bounded (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedEnum a => Enum (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedEq b => Eq (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedFloating a => Floating (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedFractional a => Fractional (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedIntegral a => Integral (Tagged s a)Defined in tagged-0.8.9 · Data.Tagged(Data s, Data b) => Data (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedNum a => Num (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedOrd b => Ord (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedRead b => Read (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedReal a => Real (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedRealFloat a => RealFloat (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedRealFrac a => RealFrac (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedShow b => Show (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedIx b => Ix (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedIsString a => IsString (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedGeneric (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedSemigroup a => Semigroup (Tagged s a)Defined in tagged-0.8.9 · Data.Tagged(Semigroup a, Monoid a) => Monoid (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedBits a => Bits (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedFiniteBits a => FiniteBits (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedStorable a => Storable (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedNFData b => NFData (Tagged s b)Defined in tagged-0.8.9 · Data.TaggedFinite a => Finite (Tagged b a)Defined in universe-base-1.1.4 · Data.Universe.ClassUniverse a => Universe (Tagged b a)Defined in universe-base-1.1.4 · Data.Universe.Classtype Rep (Tagged s b) = D1 ('MetaData "Tagged"
"Data.Tagged"
"tagged-0.8.9-5pdNZ55IadSDEGRco0szGK"
'True) (C1 ('MetaCons "Tagged"
'PrefixI 'True) (S1 ('MetaSel ('Just "unTagged"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b)))Defined in tagged-0.8.9 · Data.Taggedtype Rep1 (Tagged s) = D1 ('MetaData "Tagged"
"Data.Tagged"
"tagged-0.8.9-5pdNZ55IadSDEGRco0szGK"
'True) (C1 ('MetaCons "Tagged"
'PrefixI 'True) (S1 ('MetaSel ('Just "unTagged"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1))Defined in tagged-0.8.9 · Data.TaggedNatural number
Invariant: numbers <= 0xffffffffffffffff use the NS constructor
Enum NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.EnumEq NaturalDefined in ghc-bignum-1.3 · GHC.Num.NaturalIntegral NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.RealData NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.DataNum NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.NumOrd NaturalDefined in ghc-bignum-1.3 · GHC.Num.NaturalRead NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.ReadReal NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.RealShow NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.ShowIx NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.IxBits NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.BitsPrintfArg NaturalDefined in base-4.20.2.0 · Text.PrintfNFData NaturalDefined in deepseq-1.5.0.0 · Control.DeepSeqUniverse NaturalDefined in universe-base-1.1.4 · Data.Universe.ClassRationalUniverse NaturalDefined in universe-base-1.1.4 · Data.Universe.ClassLift NaturalDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxTestCoercion SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNatsTestEquality SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNatstype Compare a b = CmpNat a bDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.OrdThese functions exist primarily as a specification to test against.
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.
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.