Safe Haskell | None |
---|---|
Language | Haskell2010 |
Documentation
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
xuniverse
-- any inhabitant has a finite index let pfx =take
nuniverse
-- any finite prefix of universe has unique elements inlength
pfx =length
(nub pfx)
Nothing
Instances
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
xuniverseF
-- any inhabitant has a finite indexlength
(filter
(== x)universeF
) == 1 -- should terminate (xs ->cardinality
xs ==genericLength
xs)universeF
Note:
may not hold for all types, though the laws imply that elemIndex
x universe
== elemIndex
x universeF
universe
is a permutation of universeF
.
>>>
elemIndex (Left True :: Either Bool Bool) universe
Just 2
>>>
elemIndex (Left True :: Either Bool Bool) universeF
Just 1
Nothing
Instances
Finite Bool | |
Defined in Data.Universe.Class | |
Finite Char | |
Defined in Data.Universe.Class | |
Finite Int | |
Defined in Data.Universe.Class | |
Finite Int8 | |
Defined in Data.Universe.Class | |
Finite Int16 | |
Defined in Data.Universe.Class | |
Finite Int32 | |
Defined in Data.Universe.Class | |
Finite Int64 | |
Defined in Data.Universe.Class | |
Finite Ordering | |
Defined in Data.Universe.Class | |
Finite Word | |
Defined in Data.Universe.Class | |
Finite Word8 | |
Defined in Data.Universe.Class | |
Finite Word16 | |
Defined in Data.Universe.Class | |
Finite Word32 | |
Defined in Data.Universe.Class | |
Finite Word64 | |
Defined in Data.Universe.Class | |
Finite () | |
Defined in Data.Universe.Class | |
Finite Void | |
Defined in Data.Universe.Class | |
Finite All | |
Defined in Data.Universe.Class | |
Finite Any | |
Defined in Data.Universe.Class | |
Finite a => Finite (Maybe a) | |
Defined in Data.Universe.Class | |
(Finite a, Ord a) => Finite (Predicate a) Source # |
Beware, function type universes are large...
... but thanks to laziness, you can expect at least few:
|
Defined in Data.Universe.Instances.Extended | |
Finite a => Finite (Min a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Max a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (First a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Last a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Identity a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (First a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Last a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Dual a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Sum a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Product a) | |
Defined in Data.Universe.Class | |
(Ord a, Finite a) => Finite (Set a) | |
Defined in Data.Universe.Class | |
(Ord a, Finite a, Finite b) => Finite (a -> b) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b) => Finite (Either a b) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b) => Finite (a, b) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b, Ord b) => Finite (Op a b) Source # | |
Defined in Data.Universe.Instances.Extended | |
(Representable f, Finite (Rep f), Ord (Rep f), Finite a) => Finite (Co f a) Source # | |
Defined in Data.Universe.Instances.Extended | |
Finite (Proxy a) | |
Defined in Data.Universe.Class | |
(Ord k, Finite k, Finite v) => Finite (Map k v) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b, Finite c) => Finite (a, b, c) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Const a b) | |
Defined in Data.Universe.Class | |
(Representable f, Finite s, Ord s, Finite (Rep f), Ord (Rep f), Finite a) => Finite (TracedT s f a) Source # | |
Defined in Data.Universe.Instances.Extended | |
Finite (f a) => Finite (IdentityT f a) | |
Defined in Data.Universe.Class | |
Finite a => Finite (Tagged b a) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b, Finite c, Finite d) => Finite (a, b, c, d) | |
Defined in Data.Universe.Class | |
(Finite (f a), Finite (g a)) => Finite (Product f g a) | |
Defined in Data.Universe.Class | |
(Finite (f a), Finite (g a)) => Finite (Sum f g a) | |
Defined in Data.Universe.Class | |
(Finite e, Ord e, Finite (m a)) => Finite (ReaderT e m a) | |
Defined in Data.Universe.Class | |
(Finite a, Finite b, Finite c, Finite d, Finite e) => Finite (a, b, c, d, e) | |
Defined in Data.Universe.Class | |
Finite (f (g a)) => Finite (Compose f g a) | |
Defined in Data.Universe.Class |
Orphan instances
(Finite a, Ord a) => Universe (Predicate a) Source # | |
(Finite a, Ord a) => Finite (Predicate a) Source # |
Beware, function type universes are large...
... but thanks to laziness, you can expect at least few:
|
(Universe a, Finite b, Ord b) => Universe (Op a b) Source # | |
(Representable f, Finite (Rep f), Ord (Rep f), Universe a) => Universe (Co f a) Source # | We could do this: instance Universe (f a) => Universe (Co f a) where universe = map Rep universe However, since you probably only apply Rep to functors when you want to think of them as being representable, I think it makes sense to use an instance based on the representable-ness rather than the inherent universe-ness. Please complain if you disagree! |
(Finite a, Finite b, Ord b) => Finite (Op a b) Source # | |
(Representable f, Finite (Rep f), Ord (Rep f), Finite a) => Finite (Co f a) Source # | |
(Representable f, Finite s, Ord s, Finite (Rep f), Ord (Rep f), Universe a) => Universe (TracedT s f a) Source # | |
(Representable f, Finite s, Ord s, Finite (Rep f), Ord (Rep f), Finite a) => Finite (TracedT s f a) Source # | |