!      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~Safe2finNat natural numbers.Better than GHC's built-in   for some use cases.fin displaying a structure of .explicitShow 0"Z"explicitShow 2 "S (S Z)"fin displaying a structure of .finFold .cata [] ('x' :) 2"xx"finConvert  to  toNatural 00 toNatural 22toNatural $ S $ S $ Z2finConvert  to  fromNatural 44explicitShow (fromNatural 4)"S (S (S (S Z)))"fin is printed as .To see explicit structure, use  or   None&'.12HSUVXf2H*finDivision by two.  is 0 and  is 1 as a remainder.:kind! DivMod2 Nat7DivMod2 Nat7 :: (Nat, Bool)= '( 'S ('S ('S 'Z)), 'True):kind! DivMod2 Nat4DivMod2 Nat4 :: (Nat, Bool)= '( 'S ('S 'Z), 'False)+fin Multiplication by two. Doubling.#reflect (snat :: SNat (Mult2 Nat4))8,finMultiplication.'reflect (snat :: SNat (Mult Nat2 Nat3))6-fin Addition.'reflect (snat :: SNat (Plus Nat1 Nat2))3.finConvert from GHC .:kind! FromGHC 7FromGHC 7 :: Nat%= 'S ('S ('S ('S ('S ('S ('S 'Z))))))/finConvert to GHC .:kind! ToGHC Nat5ToGHC Nat5 :: GHC.Nat= 50fin$The induction will be fully inlined.See test/Inspection.hs.2finType family used to implement   from Data.Type.Equality module.3finConvenience class to get 5.5fin Singleton of .8fin Constructor 3 dictionary from 5.9finReflect type-level  to the term level.:finAs 9 but with any .;finReify .reify nat3 reflect3<finConvert 5 to .snatToNat (snat :: SNat Nat1)1=finConvert 5 to !snatToNatural (snat :: SNat Nat0)0!snatToNatural (snat :: SNat Nat2)2>fin&Decide equality of type-level numbers.(eqNat :: Maybe (Nat3 :~: Plus Nat1 Nat2) Just Refl(eqNat :: Maybe (Nat3 :~: Mult Nat2 Nat2)Nothing?fin&Decide equality of type-level numbers.6decShow (discreteNat :: Dec (Nat3 :~: Plus Nat1 Nat2)) "Yes Refl"@fin Induction on ', functor form. Useful for computation.8induction1 (Tagged 0) $ retagMap (+2) :: Tagged Nat3 IntTagged 6Afin Induction on ..Useful in proofs or with GADTs, see source of E.BfinSee 0.CfinUnfold n steps of a general recursion.Note: Always  benchmark". This function may give you both badK properties: a lot of code (increased binary size), and worse performance. For known n C# will unfold recursion, for example C ( ::  &) f = f (f (f (fix f))) Dfin  0 + n = nEfin  n + 0 = nFfin  0 * n = 0Gfin  n * 0 = 0Hfin  1 * n = nIfin  n * 1 = n@fin zero casefininduction stepAfin zero casefininduction stepBfin zero casefininduction step<  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI<567<=348;9:>2?A@01BC-,+*/. )('&%$#"! DEFGHINone &'.12HUVXf\QfinFinite numbers: [0..n-1].TfinMirror the values,  becomes , etc.#map mirror universe :: [Fin N.Nat4] [3,2,1,0] reverse universe :: [Fin N.Nat4] [3,2,1,0]UfinMultiplicative inverse. Works for Q n where n3 is coprime with an argument, i.e. in general when n is prime.$map inverse universe :: [Fin N.Nat5] [0,1,3,2,4];zipWith (*) universe (map inverse universe) :: [Fin N.Nat5] [0,1,1,1,1]Adaptation of Khttps://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integerspseudo-code in WikipediaVfin displaying a structure of Q.explicitShow (0 :: Fin N.Nat1)"FZ"explicitShow (2 :: Fin N.Nat3) "FS (FS FZ)"Wfin displaying a structure of Q.XfinFold Q.Yfin Convert to .Zfin Convert from .$fromNat N.nat1 :: Maybe (Fin N.Nat2)Just 1$fromNat N.nat1 :: Maybe (Fin N.Nat1)Nothing[fin Convert to .finConvert from any  .\fin All values. [minBound .. maxBound] won't work for Q ).universe :: [Fin N.Nat3][0,1,2]]finLike \ but ."universe1 :: NonEmpty (Fin N.Nat3) 0 :| [1,2]^fin\! which will be fully inlined, if n is known at compile time.inlineUniverse :: [Fin N.Nat3][0,1,2]_fin(inlineUniverse1 :: NonEmpty (Fin N.Nat3) 0 :| [1,2]`finQ ) is not inhabited.afinCounting to one is boring.boring0bfinReturn a one less.isMin (FZ :: Fin N.Nat1)Nothing*map isMin universe :: [Maybe (Fin N.Nat3)][Nothing,Just 0,Just 1,Just 2]cfinReturn a one less.isMax (FZ :: Fin N.Nat1)Nothing*map isMax universe :: [Maybe (Fin N.Nat3)][Just 0,Just 1,Just 2,Nothing]dfin)map weakenRight1 universe :: [Fin N.Nat5] [1,2,3,4]efin(map weakenLeft1 universe :: [Fin N.Nat5] [0,1,2,3]ffinCmap (weakenLeft (Proxy :: Proxy N.Nat2)) (universe :: [Fin N.Nat3])[0,1,2]gfinDmap (weakenRight (Proxy :: Proxy N.Nat2)) (universe :: [Fin N.Nat3])[2,3,4]hfin Append two Q s together.6append (Left fin2 :: Either (Fin N.Nat5) (Fin N.Nat4))27append (Right fin2 :: Either (Fin N.Nat5) (Fin N.Nat4))7ifin Inverse of h..split fin2 :: Either (Fin N.Nat2) (Fin N.Nat3)Right 0.split fin1 :: Either (Fin N.Nat2) (Fin N.Nat3)Left 18map split universe :: [Either (Fin N.Nat2) (Fin N.Nat3)]'[Left 0,Left 1,Right 0,Right 1,Right 2]yfin works only on Q n where n is prime.{finOperations module n.3map fromInteger [0, 1, 2, 3, 4, -5] :: [Fin N.Nat3] [0,1,2,0,1,1]fromInteger 42 :: Fin N.Nat0*** Exception: divide by zero...signum (FZ :: Fin N.Nat1)0signum (3 :: Fin N.Nat4)12 + 3 :: Fin N.Nat412 * 3 :: Fin N.Nat42|finQ is printed as .To see explicit structure, use V or W$QRSTUVWXYZ[\]^_`abcdefghijklmnopqrs$QRSXVWYZ[TU\^]_`afegdhibcjklmnopqrsNone,-.8=>?@AHUVXg|fin'Constraint for the class that computes .fin'Constraint for the class that computes .finCompute the size from the type.finGeneric enumerations. Examples:from ()0 to 0 :: ()() to 0 :: BoolFalsemap to F.universe :: [Bool] [False,True]Qmap (to . (+1) . from) [LT, EQ, GT] :: [Ordering] -- Num Fin is modulo arithmetic [EQ,GT,LT]finThe size of an enumeration.finConverts a value to its index.fin*Converts from index to the original value.finGeneric version of .finGeneric version of .fin ~ +fin ~ 3fin ~ 2fin() ~ 1finVoid ~ 0 None&'.12=>?@ASUVXfyfinTotal order of , less-than-or-Equal-to,  \le .finAn evidence of n \le m.  zero+succ definition.fin Constructor  dictionary from .fin \forall n : \mathbb{N}, 0 \le n fin8\forall n\, m : \mathbb{N}, n \le m \to 1 + n \le 1 + m fin8\forall n\, m : \mathbb{N}, 1 + n \le 1 + m \to n \le m fin \forall n : \mathbb{N}, n \le n fin4\forall n\, m : \mathbb{N}, n \le m \to n \le 1 + m fin4\forall n\, m : \mathbb{N}, 1 + n \le m \to n \le m fin?\forall n\, m : \mathbb{N}, n \le m \to m \le n \to n \equiv m fin@\forall n\, m\, p : \mathbb{N}, n \le m \to m \le p \to n \le p fin;\forall n\, m : \mathbb{N}, \neg (n \le m) \to 1 + m \le n fin;\forall n\, m : \mathbb{N}, n \le m \to \neg (1 + m \le n) leProof :: LEProof Nat2 Nat3LESucc (LESucc LEZero)/leSwap (leSwap' (leProof :: LEProof Nat2 Nat3))LESucc (LESucc (LESucc LEZero))8lePred (leSwap (leSwap' (leProof :: LEProof Nat2 Nat3)))LESucc (LESucc LEZero)fin Find the  n m, i.e. compare numbers.fin0\forall n\ : \mathbb{N}, n \le 0 \to n \equiv 0 fin values are unique (not Boring though!).None&'.12=>?@AUVXf-finAn evidence of n \le m.  refl+step definition.fin Convert from  zero+succ to  refl+step definition. Inverse of .finConvert  refl+step to  zero+succ definition. Inverse of .fin \forall n : \mathbb{N}, 0 \le n fin8\forall n\, m : \mathbb{N}, n \le m \to 1 + n \le 1 + m fin8\forall n\, m : \mathbb{N}, 1 + n \le 1 + m \to n \le m fin \forall n : \mathbb{N}, n \le n fin4\forall n\, m : \mathbb{N}, n \le m \to n \le 1 + m fin4\forall n\, m : \mathbb{N}, 1 + n \le m \to n \le m fin?\forall n\, m : \mathbb{N}, n \le m \to m \le n \to n \equiv m fin@\forall n\, m\, p : \mathbb{N}, n \le m \to m \le p \to n \le p fin;\forall n\, m : \mathbb{N}, \neg (n \le m) \to 1 + m \le n fin;\forall n\, m : \mathbb{N}, n \le m \to \neg (1 + m \le n) fin Find the  n m, i.e. compare numbers.fin0\forall n\ : \mathbb{N}, n \le 0 \to n \equiv 0 fin values are unique (not Boring though!).None&'.=>?@AHSUVXfinLess-Than-or. <. Well-founded relation on .GHC can solve this for us!ltProof :: LTProof Nat0 Nat4 LESucc LEZeroltProof :: LTProof Nat2 Nat4LESucc (LESucc (LESucc LEZero))ltProof :: LTProof Nat3 Nat3... ...error......fin An evidence n < m# which is the same as (1 + n le m).fin'\forall n : \mathbb{N}, n < n \to \bot fin5\forall n\, m : \mathbb{N}, n < m \to m < n \to \bot fin:\forall n\, m\, p : \mathbb{N}, n < m \to m < p \to n < p    !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~       fin-0.1.1-CmlKX4I25sbDg8chH2xNz3Data.FinData.Nat Data.Type.Nat Data.Fin.EnumData.Type.Nat.LEData.Type.Nat.LE.ReflStepData.Type.Nat.LT GHC.TypeLitsNatData.Type.Equality==baseGHC.Real toIntegerZS explicitShowexplicitShowsPreccata toNatural fromNaturalnat0nat1nat2nat3nat4nat5nat6nat7nat8nat9 $fFunctionNat$fCoArbitraryNat$fArbitraryNat $fHashableNat $fNFDataNat $fEnumNat $fIntegralNat $fRealNat$fNumNat $fShowNat$fEqNat$fOrdNat $fDataNatNat9Nat8Nat7Nat6Nat5Nat4Nat3Nat2Nat1Nat0DivMod2Mult2MultPlusFromGHCToGHCInlineInductioninlineInduction1EqNatSNatIsnatSNatSZSSwithSNatreflect reflectToNumreify snatToNat snatToNaturaleqNat discreteNat induction1 inductioninlineInduction unfoldedFixproofPlusZeroNproofPlusNZeroproofMultZeroNproofMultNZero proofMultOneN proofMultNOne$fTestEqualityNatSNat$fSNatIS$fSNatIZ$fInlineInductionS$fInlineInductionZ $fShowTagged $fShowSNatFinFZFSmirrorinversetoNatfromNatuniverse universe1inlineUniverseinlineUniverse1absurdboringisMinisMax weakenRight1 weakenLeft1 weakenLeft weakenRightappendsplitfin0fin1fin2fin3fin4fin5fin6fin7fin8fin9 $fFunctionFin$fCoArbitraryFin $fHashableFin $fNFDataFin $fEnumFin $fIntegralFin $fRealFin$fNumFin $fShowFin $fBoundedFin$fArbitraryFin$fOrdFin$fEqFinGToGFrom GEnumSizeEnumEnumSizefromtogfromgto $fGFromRepU1 $fGFromRepV1 $fGFromRepM1 $fGFromRep:+: $fGToRepU1 $fGToRepV1 $fGToRepM1 $fGToRep:+: $fEnumEither$fEnumOrdering $fEnumBool$fEnum() $fEnumVoidLEleProofLEProofLEZeroLESucc withLEProofleZeroleSucclePredleReflleStepleStepLleAsymleTransleSwapleSwap'decideLEproofZeroLEZero$fDecidableLEProof $fOrdLEProof $fEqLEProof$fLESm$fLEZm $fShowLEProofLEReflLEStep fromZeroSucc toZeroSuccLTltProofLTProof withLTProof ltReflAbsurd ltSymAbsurdltTrans$fLTnmGHC.Showshow showsPrec GHC.NaturalNaturalghc-prim GHC.TypesFalseTrueGHC.NumNum Data.ProxyProxyGHC.EnumminBoundmaxBound unsafeFromNum GHC.ClassesOrdGHC.BaseNonEmptyquot Data.EitherEitherOrderingBool