Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Finite numbers.
This module is designed to be imported qualified.
- data Fin n where
- cata :: forall a n. a -> (a -> a) -> Fin n -> a
- explicitShow :: Fin n -> String
- explicitShowsPrec :: Int -> Fin n -> ShowS
- toNat :: Fin n -> Nat
- fromNat :: SNatI n => Nat -> Maybe (Fin n)
- toNatural :: Fin n -> Natural
- toInteger :: Integral a => a -> Integer
- inverse :: forall n. SNatI n => Fin n -> Fin n
- universe :: SNatI n => [Fin n]
- inlineUniverse :: InlineInduction n => [Fin n]
- absurd :: Fin Zero -> b
- boring :: Fin One
- zeroth :: Fin (S n)
- first :: Fin (S (S n))
Documentation
Finite Numbers up to n
.
((~) Nat n (S m), SNatI m) => Bounded (Fin n) Source # | |
SNatI n => Enum (Fin n) Source # | |
Eq (Fin n) Source # | |
SNatI n => Integral (Fin n) Source # | |
SNatI n => Num (Fin n) Source # | Operations module
|
Ord (Fin n) Source # | |
SNatI n => Real (Fin n) Source # | |
Show (Fin n) Source # | To see explicit structure, use |
NFData (Fin n) Source # | |
Hashable (Fin n) Source # | |
Showing
explicitShow :: Fin n -> String Source #
Conversions
fromNat :: SNatI n => Nat -> Maybe (Fin n) Source #
Convert from Nat
.
>>>
fromNat N.one :: Maybe (Fin N.Two)
Just 1
>>>
fromNat N.one :: Maybe (Fin N.One)
Nothing
Interesting
inverse :: forall n. SNatI n => Fin n -> Fin n Source #
Multiplicative inverse.
Works for
where Fin
nn
is coprime with an argument, i.e. in general when n
is prime.
>>>
map inverse universe :: [Fin N.Five]
[0,1,3,2,4]
>>>
zipWith (*) universe (map inverse universe) :: [Fin N.Five]
[0,1,1,1,1]
Adaptation of pseudo-code in Wikipedia
inlineUniverse :: InlineInduction n => [Fin n] Source #
.SNatI universe
which will be fully inlined, if n
is known at compile time.
>>>
inlineUniverse :: [Fin N.Three]
[0,1,2]