Safe Haskell | None |
---|---|
Language | GHC2021 |
Data.Fin
Contents
Description
Synopsis
- data Nat
- data SNat (n :: Nat) where
- data Fin (n :: Nat) where
- toNat :: forall (n :: Nat). Fin n -> Nat
- fromNat :: forall (n :: Nat). SNatI n => Nat -> Maybe (Fin n)
- toInteger :: Integral a => a -> Integer
- mirror :: forall (n :: Nat). SNatI n => Fin n -> Fin n
- absurd :: Fin Nat0 -> b
- universe :: forall (n :: Nat). SNatI n => [Fin n]
- f0 :: forall (n :: Nat). Fin ('S n)
- f1 :: forall (n :: Nat). Fin ('S ('S n))
- f2 :: forall (n :: Nat). Fin ('S ('S ('S n)))
- f3 :: forall (n :: Nat). Fin ('S ('S ('S ('S n))))
- invert :: forall (n :: Nat). SNatI n => Fin n -> Fin n
- shiftN :: forall (n :: Nat) (m :: Nat). SNat n -> Fin m -> Fin (n + m)
- shift1 :: forall (m :: Nat). Fin m -> Fin ('S m)
- weakenFin :: forall proxy (m :: Nat) (n :: Nat). proxy m -> Fin n -> Fin (m + n)
- weakenFinRight :: forall proxy (m :: Nat) (n :: Nat). proxy m -> Fin n -> Fin (n + m)
- weaken1Fin :: forall (n :: Nat). Fin n -> Fin ('S n)
- weaken1FinRight :: forall (n :: Nat). Fin n -> Fin (n + N1)
- strengthen1Fin :: forall (n :: Nat). SNatI n => Fin ('S n) -> Maybe (Fin n)
- strengthenRecFin :: forall (k :: Nat) (m :: Nat) proxy (n :: Nat). SNat k -> SNat m -> proxy n -> Fin (k + (m + n)) -> Maybe (Fin (k + n))
Documentation
Nat natural numbers.
Better than GHC's built-in Nat
for some use cases.
Instances
Arbitrary Nat | |
CoArbitrary Nat | |
Function Nat | |
Data Nat | |
Defined in Data.Nat Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Nat -> c Nat # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Nat # dataTypeOf :: Nat -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Nat) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Nat) # gmapT :: (forall b. Data b => b -> b) -> Nat -> Nat # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Nat -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Nat -> r # gmapQ :: (forall d. Data d => d -> u) -> Nat -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Nat -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Nat -> m Nat # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Nat -> m Nat # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Nat -> m Nat # | |
Enum Nat | |
Num Nat | |
Integral Nat | |
Real Nat | |
Defined in Data.Nat Methods toRational :: Nat -> Rational # | |
Show Nat | To see explicit structure, use |
NFData Nat | |
Eq Nat | |
Ord Nat | |
Hashable Nat | |
Universe Nat |
Since: fin-0.1.2 |
Category LEProof | The other variant ( |
TestEquality SNat | |
Defined in Data.Type.Nat | |
TestEquality PatN Source # | |
Defined in Rebound.Bind.PatN | |
EqP Fin |
Since: fin-0.2.2 |
EqP SNat | Since: fin-0.2.2 |
GNFData SNat | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
GCompare SNat | Since: fin-0.2.1 |
GEq SNat | Since: fin-0.2.1 |
GShow Fin | Since: fin-0.2.2 |
GShow SNat | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
OrdP Fin |
Since: fin-0.2.2 |
OrdP SNat | Since: fin-0.2.2 |
GSubst b (V1 :: Nat -> Type) Source # | |
GSubst v (U1 :: Nat -> Type) Source # | |
Generic1 (List a :: Nat -> Type) Source # | Enable generic programming for the |
Defined in Data.Scoped.List | |
Generic1 (Maybe a :: Nat -> Type) Source # | |
Defined in Data.Scoped.Maybe | |
Subst b g => GSubst b (Rec1 g) Source # | |
Subst v t => Subst v (List t) Source # | |
(GSubst b f, GSubst b g) => GSubst b (f :*: g) Source # | |
(GSubst b f, GSubst b g) => GSubst b (f :+: g) Source # | |
GSubst v (K1 i c :: Nat -> Type) Source # | |
GSubst b f => GSubst b (M1 i c f) Source # | |
GFV (U1 :: Nat -> Type) Source # | |
GFV (V1 :: Nat -> Type) Source # | |
GStrengthen (U1 :: Nat -> Type) Source # | |
GStrengthen (V1 :: Nat -> Type) Source # | |
FV t => FV (List t) Source # | |
FV t => GFV (Rec1 t) Source # | |
Strengthen t => GStrengthen (Rec1 t) Source # | |
Strengthen t => Strengthen (List t) Source # | |
(GFV f, GFV g) => GFV (f :*: g) Source # | |
(GFV f, GFV g) => GFV (f :+: g) Source # | |
GFV (K1 i c :: Nat -> Type) Source # | |
(GStrengthen f, GStrengthen g) => GStrengthen (f :*: g) Source # | |
(GStrengthen f, GStrengthen g) => GStrengthen (f :+: g) Source # | |
GStrengthen (K1 i c :: Nat -> Type) Source # | |
GFV f => GFV (M1 i c f) Source # | |
GStrengthen f => GStrengthen (M1 i c f) Source # | |
type Rep1 (List a :: Nat -> Type) Source # | |
type Rep1 (Maybe a :: Nat -> Type) Source # | |
Singleton of Nat
.
Bundled Patterns
pattern SS' :: forall m n. () => m ~ 'S n => SNat n -> SNat m | A pattern with explicit argument
Since: fin-0.3.2 |
Instances
TestEquality SNat | |
Defined in Data.Type.Nat | |
EqP SNat | Since: fin-0.2.2 |
GNFData SNat | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
GCompare SNat | Since: fin-0.2.1 |
GEq SNat | Since: fin-0.2.1 |
GShow SNat | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
OrdP SNat | Since: fin-0.2.2 |
SNatI n => Arbitrary (SNat n) Source # | |
Show (SNat p) | |
SNatI n => Boring (SNat n) | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
NFData (SNat n) | Since: fin-0.2.1 |
Defined in Data.Type.Nat | |
Eq (SNat a) | Since: fin-0.2.2 |
Ord (SNat a) | Since: fin-0.2.2 |
ToInt (SNat n) Source # | |
Sized (SNat n) Source # | |
PatEq (SNat n1) (SNat n2) Source # | |
type Size (SNat n) Source # | |
Defined in Rebound.Classes |
Finite numbers: [0..n-1]
.
Instances
FV Fin Source # | |
Shiftable Fin Source # | |
Strengthen Fin Source # | |
SubstVar Fin Source # | |
GSubst b Fin Source # | |
Subst Fin Fin Source # | |
SubstVar v => Subst v Fin Source # | |
EqP Fin |
Since: fin-0.2.2 |
GShow Fin | Since: fin-0.2.2 |
OrdP Fin |
Since: fin-0.2.2 |
(n ~ 'S m, SNatI m) => Arbitrary (Fin n) | |
CoArbitrary (Fin n) | |
(n ~ 'S m, SNatI m) => Function (Fin n) | |
(n ~ 'S m, SNatI m) => Bounded (Fin n) | |
SNatI n => Enum (Fin n) | |
SNatI n => Num (Fin n) | Operations module
|
SNatI n => Integral (Fin n) | |
SNatI n => Real (Fin n) | |
Defined in Data.Fin Methods toRational :: Fin n -> Rational # | |
Show (Fin n) | To see explicit structure, use |
n ~ 'Z => Absurd (Fin n) | Since: fin-0.2.1 |
NFData (Fin n) | |
Eq (Fin n) | |
Ord (Fin n) | |
Hashable (Fin n) | |
ToInt (Fin n) Source # | The |
SNatI n => Finite (Fin n) |
Since: fin-0.1.2 |
SNatI n => Universe (Fin n) | Since: fin-0.1.2 |
SNatI n => FoldableWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
Defined in Data.Vec.DataFamily.SpineStrict | |
FoldableWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
Defined in Data.Vec.Lazy | |
SNatI n => FoldableWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
Defined in Data.Vec.Pull | |
SNatI n => FunctorWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
FunctorWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
FunctorWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
SNatI n => TraversableWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
Defined in Data.Vec.DataFamily.SpineStrict | |
TraversableWithIndex (Fin n) (Vec n) | Since: vec-0.4 |
Defined in Data.Vec.Lazy |
fromNat :: forall (n :: Nat). SNatI n => Nat -> Maybe (Fin n) #
Convert from Nat
.
>>>
fromNat N.nat1 :: Maybe (Fin N.Nat2)
Just 1
>>>
fromNat N.nat1 :: Maybe (Fin N.Nat1)
Nothing
invert :: forall (n :: Nat). SNatI n => Fin n -> Fin n Source #
List all numbers up to some size >>> universe :: [Fin N3] [0,1,2]
Convert an "index" Fin to a "level" Fin and vice versa.
shiftN :: forall (n :: Nat) (m :: Nat). SNat n -> Fin m -> Fin (n + m) Source #
Increment by a fixed amount (on the left).
weakenFin :: forall proxy (m :: Nat) (n :: Nat). proxy m -> Fin n -> Fin (m + n) Source #
Weaken the bound of a Fin
by an arbitrary amount, without
changing its index.
Weakenening changes the bound of a nat-indexed type without changing its value. These operations can either be defined for the n-ary case (as in Fin below) or be defined in terms of a single-step operation. However, as both of these operations are identity functions, it is justified to use unsafeCoerce.
The corresponding function in the Data.Fin library is weakenLeft
.
-- >>> :t weakenLeft weakenLeft :: SNatI n => Proxy m -> Fin n -> Fin (Plus n m)
This function does not change the value, it only changes its type.
-- >>> weakenLeft (Proxy :: Proxy N1) (f1 :: Fin N2) :: Fin N3 1
We could use the following definition:
weakenFin m f = withSNat m $ weakenLeft (Proxy :: Proxy m) f
But, by using an unsafeCoerce
implementation, we can avoid the
constraint in the type of this operation.SNatI
n
-- >>> weakenFin (Proxy :: Proxy N1) (f1 :: Fin N2) :: Fin N3 1
weakenFinRight :: forall proxy (m :: Nat) (n :: Nat). proxy m -> Fin n -> Fin (n + m) Source #
Weaken the bound of of a Fin
by an arbitrary amount on the right.
This is also an identity function
>>> weakenFinRight (s1 :: SNat N1) (f1 :: Fin N2) :: Fin N3
1
strengthen1Fin :: forall (n :: Nat). SNatI n => Fin ('S n) -> Maybe (Fin n) Source #
With strengthening, we make sure that variable f0 is not used, and we decrement all other indices by 1. This allows us to also decrement the scope by one.
strengthenRecFin :: forall (k :: Nat) (m :: Nat) proxy (n :: Nat). SNat k -> SNat m -> proxy n -> Fin (k + (m + n)) -> Maybe (Fin (k + n)) Source #
We implement strengthening with the following operation that
generalizes the induction hypothesis, so that we can strengthen
in the middle of the scope. The scope of the Fin should have the form
k + (m + n)
Indices in the middle part of the scope m
are "strengthened" away.