| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Ouroboros.Consensus.Util.Counting
Description
Type-level counting
Intended for unqualified import.
Synopsis
- newtype Exactly xs a where
- Exactly {
- getExactly :: NP (K a) xs
- pattern ExactlyNil :: () => xs ~ '[] => Exactly xs a
- pattern ExactlyCons :: () => xs' ~ (x ': xs) => a -> Exactly xs a -> Exactly xs' a
- Exactly {
- data AtMost :: [Type] -> Type -> Type where
- AtMostNil :: AtMost xs a
- AtMostCons :: !a -> !(AtMost xs a) -> AtMost (x ': xs) a
- data NonEmpty :: [Type] -> Type -> Type where
- NonEmptyOne :: !a -> NonEmpty (x ': xs) a
- NonEmptyCons :: !a -> !(NonEmpty xs a) -> NonEmpty (x ': xs) a
- exactlyOne :: a -> Exactly '[x] a
- exactlyTwo :: a -> a -> Exactly '[x, y] a
- exactlyHead :: Exactly (x ': xs) a -> a
- exactlyTail :: Exactly (x ': xs) a -> Exactly xs a
- exactlyZip :: Exactly xs a -> Exactly xs b -> Exactly xs (a, b)
- exactlyZipFoldable :: Foldable t => Exactly xs a -> t b -> AtMost xs (a, b)
- exactlyWeaken :: Exactly xs a -> AtMost xs a
- exactlyWeakenNonEmpty :: Exactly (x ': xs) a -> NonEmpty (x ': xs) a
- exactlyReplicate :: forall a r. Word -> a -> (forall xs. Exactly xs a -> r) -> r
- atMostOne :: a -> AtMost (x ': xs) a
- atMostInit :: AtMost xs a -> Maybe (AtMost xs a, a)
- atMostHead :: AtMost xs a -> Maybe a
- atMostLast :: AtMost xs a -> Maybe a
- atMostZipFoldable :: Foldable t => AtMost xs a -> t b -> AtMost xs (a, b)
- atMostNonEmpty :: AtMost (x ': xs) a -> Maybe (NonEmpty (x ': xs) a)
- nonEmptyHead :: NonEmpty xs a -> a
- nonEmptyLast :: NonEmpty xs a -> a
- nonEmptyInit :: NonEmpty xs a -> (Maybe (NonEmpty xs a), a)
- nonEmptyFromList :: forall xs a. SListI xs => [a] -> Maybe (NonEmpty xs a)
- nonEmptyWeaken :: NonEmpty xs a -> AtMost xs a
- nonEmptyStrictPrefixes :: NonEmpty xs a -> [NonEmpty xs a]
- nonEmptyMapOne :: forall m xs a. Alternative m => (a -> m a) -> NonEmpty xs a -> m (NonEmpty xs a)
- nonEmptyMapTwo :: forall m xs a. Alternative m => (a -> m a) -> (a -> a -> m (a, a)) -> NonEmpty xs a -> m (NonEmpty xs a)
Documentation
Constructors
| Exactly | |
Fields
| |
Bundled Patterns
| pattern ExactlyNil :: () => xs ~ '[] => Exactly xs a | |
| pattern ExactlyCons :: () => xs' ~ (x ': xs) => a -> Exactly xs a -> Exactly xs' a |
Instances
| Functor (Exactly xs) Source # | |
| Foldable (Exactly xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting Methods fold :: Monoid m => Exactly xs m -> m # foldMap :: Monoid m => (a -> m) -> Exactly xs a -> m # foldMap' :: Monoid m => (a -> m) -> Exactly xs a -> m # foldr :: (a -> b -> b) -> b -> Exactly xs a -> b # foldr' :: (a -> b -> b) -> b -> Exactly xs a -> b # foldl :: (b -> a -> b) -> b -> Exactly xs a -> b # foldl' :: (b -> a -> b) -> b -> Exactly xs a -> b # foldr1 :: (a -> a -> a) -> Exactly xs a -> a # foldl1 :: (a -> a -> a) -> Exactly xs a -> a # toList :: Exactly xs a -> [a] # null :: Exactly xs a -> Bool # length :: Exactly xs a -> Int # elem :: Eq a => a -> Exactly xs a -> Bool # maximum :: Ord a => Exactly xs a -> a # minimum :: Ord a => Exactly xs a -> a # | |
| Traversable (Exactly xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting | |
| Eq a => Eq (Exactly xs a) Source # | |
| Show a => Show (Exactly xs a) Source # | |
data AtMost :: [Type] -> Type -> Type where Source #
At most one value for each type level index
Constructors
| AtMostNil :: AtMost xs a | |
| AtMostCons :: !a -> !(AtMost xs a) -> AtMost (x ': xs) a |
Instances
| Functor (AtMost xs) Source # | |
| Foldable (AtMost xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting Methods fold :: Monoid m => AtMost xs m -> m # foldMap :: Monoid m => (a -> m) -> AtMost xs a -> m # foldMap' :: Monoid m => (a -> m) -> AtMost xs a -> m # foldr :: (a -> b -> b) -> b -> AtMost xs a -> b # foldr' :: (a -> b -> b) -> b -> AtMost xs a -> b # foldl :: (b -> a -> b) -> b -> AtMost xs a -> b # foldl' :: (b -> a -> b) -> b -> AtMost xs a -> b # foldr1 :: (a -> a -> a) -> AtMost xs a -> a # foldl1 :: (a -> a -> a) -> AtMost xs a -> a # toList :: AtMost xs a -> [a] # length :: AtMost xs a -> Int # elem :: Eq a => a -> AtMost xs a -> Bool # maximum :: Ord a => AtMost xs a -> a # minimum :: Ord a => AtMost xs a -> a # | |
| Traversable (AtMost xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting | |
| Eq a => Eq (AtMost xs a) Source # | |
| Show a => Show (AtMost xs a) Source # | |
data NonEmpty :: [Type] -> Type -> Type where Source #
Non-empty variation on AtMost
Constructors
| NonEmptyOne :: !a -> NonEmpty (x ': xs) a | |
| NonEmptyCons :: !a -> !(NonEmpty xs a) -> NonEmpty (x ': xs) a |
Instances
| Functor (NonEmpty xs) Source # | |
| IsNonEmpty xs => Applicative (NonEmpty xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting | |
| Foldable (NonEmpty xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting Methods fold :: Monoid m => NonEmpty xs m -> m # foldMap :: Monoid m => (a -> m) -> NonEmpty xs a -> m # foldMap' :: Monoid m => (a -> m) -> NonEmpty xs a -> m # foldr :: (a -> b -> b) -> b -> NonEmpty xs a -> b # foldr' :: (a -> b -> b) -> b -> NonEmpty xs a -> b # foldl :: (b -> a -> b) -> b -> NonEmpty xs a -> b # foldl' :: (b -> a -> b) -> b -> NonEmpty xs a -> b # foldr1 :: (a -> a -> a) -> NonEmpty xs a -> a # foldl1 :: (a -> a -> a) -> NonEmpty xs a -> a # toList :: NonEmpty xs a -> [a] # null :: NonEmpty xs a -> Bool # length :: NonEmpty xs a -> Int # elem :: Eq a => a -> NonEmpty xs a -> Bool # maximum :: Ord a => NonEmpty xs a -> a # minimum :: Ord a => NonEmpty xs a -> a # | |
| Traversable (NonEmpty xs) Source # | |
Defined in Ouroboros.Consensus.Util.Counting | |
| Eq a => Eq (NonEmpty xs a) Source # | |
| Show a => Show (NonEmpty xs a) Source # | |
Working with Exactly
exactlyOne :: a -> Exactly '[x] a Source #
Singleton
exactlyTwo :: a -> a -> Exactly '[x, y] a Source #
From a pair
exactlyHead :: Exactly (x ': xs) a -> a Source #
Analogue of head
exactlyZipFoldable :: Foldable t => Exactly xs a -> t b -> AtMost xs (a, b) Source #
Analogue of zip where the length of second argument is unknown
exactlyWeaken :: Exactly xs a -> AtMost xs a Source #
exactlyWeakenNonEmpty :: Exactly (x ': xs) a -> NonEmpty (x ': xs) a Source #
exactlyReplicate :: forall a r. Word -> a -> (forall xs. Exactly xs a -> r) -> r Source #
Analogue of replicate
In CPS style because the xs type parameter is not statically known.
Working with AtMost
atMostInit :: AtMost xs a -> Maybe (AtMost xs a, a) Source #
Analogue of init
For simplicity we don't shrink the type-level index.
Working with NonEmpty
nonEmptyHead :: NonEmpty xs a -> a Source #
Analogue of head
nonEmptyLast :: NonEmpty xs a -> a Source #
Analogue of last
nonEmptyWeaken :: NonEmpty xs a -> AtMost xs a Source #
nonEmptyStrictPrefixes :: NonEmpty xs a -> [NonEmpty xs a] Source #
A strict prefixes
nonEmptyStrictPrefixes (fromJust (nonEmptyFromList [1..4])) == [ NonEmptyOne 1 , NonEmptyCons 1 $ NonEmptyOne 2 , NonEmptyCons 1 $ NonEmptyCons 2 $ NonEmptyOne 3 ]
nonEmptyMapOne :: forall m xs a. Alternative m => (a -> m a) -> NonEmpty xs a -> m (NonEmpty xs a) Source #
Apply the specified function to exactly one element
nonEmptyMapTwo :: forall m xs a. Alternative m => (a -> m a) -> (a -> a -> m (a, a)) -> NonEmpty xs a -> m (NonEmpty xs a) Source #
Variation on nonEmptyMapOne where we try to apply the function to
pairs of elements