HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerebase-1.21.2Haskell2010

Rebase.GHC.TypeNats

  • 6 types
  • 1 class
  • 9 values
  • Packagerebase-1.21.2
  • Exports25
  • LanguageHaskell2010
  • LicenceMIT
  • SourceNatural.hs
datadata Natural
#

Natural number

Invariant: numbers <= 0xffffffffffffffff use the NS constructor

Instances20Enum, Eq, Integral, Data, Num, Ord, …
  • Enum NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural
  • Integral NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Data NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Num

    Note that Natural's Num instance isn't a ring: no element but 0 has an additive inverse. It is a semiring though.

  • Ord NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural
  • Read NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Show NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Bits NaturalDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • PrintfArg NaturalDefined in base-4.20.2.0 · Text.Printf
  • NFData NaturalDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • UniformRange NaturalDefined in random-1.2.1.3 · System.Random.Internal
  • Binary NaturalDefined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable NaturalDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • Lift NaturalDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • TestCoercion SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • TestEquality SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • type Compare a b = CmpNat a bDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Ord
typetype (<=) (x :: t) (y :: t) = Assert (x <=? y) (LeErrMsg x y)
#

Comparison (<=) of comparable types, as a constraint.

classclass KnownNat (n :: Nat) where
#

This class gives the integer associated with a type-level natural. There are instances of the class for every concrete literal: 0, 1, 2, etc.

Methods

typetype Nat = Natural
#

A type synonym for Natural.

Previously, this was an opaque data type, but it was changed to a type synonym.

Instances1HasResolution
  • KnownNat n => HasResolution nDefined in base-4.20.2.0 · Data.Fixed

    For example, Fixed 1000 will give you a Fixed with a resolution of 1000.

familytype family Log2 (a :: Natural) :: Natural
#

Log base 2 (round down) of natural numbers. Log 0 is undefined (i.e., it cannot be reduced).

familytype family Mod (a :: Natural) (b :: Natural) :: Natural
#

Modulus of natural numbers. Mod x 0 is undefined (i.e., it cannot be reduced).

familytype family Div (a :: Natural) (b :: Natural) :: Natural
#

Division (round down) of natural numbers. Div x 0 is undefined (i.e., it cannot be reduced).

newtypenewtype SNat (n :: Nat)
#

A value-level witness for a type-level natural number. This is commonly referred to as a singleton type, as for each n, there is a single value that inhabits the type SNat n (aside from bottom).

The definition of SNat is intentionally left abstract. To obtain an SNat value, use one of the following:

  1. The natSing method of KnownNat.

  2. The SNat pattern synonym.

  3. The withSomeSNat function, which creates an SNat from a Natural number.

Instances5TestCoercion, TestEquality, Eq, Ord, Show
  • TestCoercion SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • TestEquality SNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Eq (SNat n)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Ord (SNat n)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Show (SNat n)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
patternpattern SNat :: () => KnownNat n => SNat n
#

A explicitly bidirectional pattern synonym relating an SNat to a KnownNat constraint.

As an expression: Constructs an explicit SNat n value from an implicit KnownNat n constraint:

SNat @n :: KnownNat n => SNat n

As a pattern: Matches on an explicit SNat n value bringing an implicit KnownNat n constraint into scope:

f :: SNat n -> ..
f SNat = {- KnownNat n in scope -}
valuedecideNat
  1. :: (KnownNat a, KnownNat b)
  2. => proxy1 a
  3. -> proxy2 b
  4. -> Either (a :~: b -> Void) (a :~: b)
#

We either get evidence that this function was instantiated with the same type-level numbers, or that the type-level numbers are distinct.

datadata SomeNat
#

This type represents unknown type-level natural numbers.

Constructors

Instances4Eq, Ord, Read, Show
  • Eq SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Ord SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Read SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats
  • Show SomeNatDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeNats