Safe Haskell | None |
---|---|
Language | GHC2021 |
Data.SNat
Contents
Description
Runtime data that connects to type-level nats.
Synopsis
- data Nat
- toNatural :: Nat -> Natural
- fromNatural :: Natural -> Nat
- data SNat (n :: Nat) where
- snatToNat :: forall (n :: Nat). SNat n -> Nat
- class SNatI (n :: Nat) where
- snat :: forall (n :: Nat). SNatI n => SNat n
- withSNat :: forall (n :: Nat) r. SNat n -> (SNatI n => r) -> r
- reify :: Nat -> (forall (n :: Nat). SNatI n => Proxy n -> r) -> r
- reflect :: forall (n :: Nat) proxy. SNatI n => proxy n -> Nat
- type family (n :: Nat) + (m :: Nat) :: Nat where ...
- type N0 = 'Z
- type N1 = 'S N0
- type N2 = 'S N1
- type N3 = 'S N2
- s0 :: SNat N0
- s1 :: SNat N1
- s2 :: SNat N2
- s3 :: SNat N3
- sPlus :: forall (n1 :: Nat) (n2 :: Nat). SNat n1 -> SNat n2 -> SNat (n1 + n2)
- axiomPlusZ :: forall (m :: Nat). (m + 'Z) :~: m
- axiomAssoc :: forall (p :: Nat) (m :: Nat) (n :: Nat). (p + (m + n)) :~: ((p + m) + n)
- data SNat_ (n :: Nat) where
- snat_ :: forall (n :: Nat). SNat n -> SNat_ n
- prev :: forall (n :: Nat). SNat ('S n) -> SNat n
- next :: forall (n :: Nat). SNat n -> SNat ('S n)
- class ToInt a where
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 # | |
fromNatural :: Natural -> Nat #
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 |
class SNatI (n :: Nat) where #
Implicit SNat
.
In an unorthodox singleton way, it actually provides an induction function.
The induction should often be fully inlined.
See test/Inspection.hs
.
>>>
:set -XPolyKinds
>>>
newtype Const a b = Const a deriving (Show)
>>>
induction (Const 0) (coerce ((+2) :: Int -> Int)) :: Const Int Nat3
Const 6
Methods
reify :: Nat -> (forall (n :: Nat). SNatI n => Proxy n -> r) -> r #
Reify Nat
.
>>>
reify nat3 reflect
3
reflect :: forall (n :: Nat) proxy. SNatI n => proxy n -> Nat #
Reflect type-level Nat
to the term level.
sPlus :: forall (n1 :: Nat) (n2 :: Nat). SNat n1 -> SNat n2 -> SNat (n1 + n2) Source #
Addition of singleton naturals.
axiomAssoc :: forall (p :: Nat) (m :: Nat) (n :: Nat). (p + (m + n)) :~: ((p + m) + n) Source #
+
is associative.
snat_ :: forall (n :: Nat). SNat n -> SNat_ n Source #
View pattern allowing pattern matching on naturals.
f :: forall p. SNat p -> ... f SZ = ... f (snat_ -> SS_ m) = ...
Conversion to Int
.