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

Modulererebase-1.21.2Haskell2010

GHC.TypeLits

  • 13 types
  • 3 classes
  • 27 values
  • Packagererebase-1.21.2
  • Exports62
  • LanguageHaskell2010
  • LicenceMIT
  • SourceTypeError.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
familytype family TypeError (a :: ErrorMessage) :: b where
#

The type-level equivalent of error.

The polymorphic kind of this type allows it to be used in several settings. For instance, it can be used as a constraint, e.g. to provide a better error message for a non-existent instance,

-- in a context
instance TypeError (Text "Cannot Show functions." :$$:
                    Text "Perhaps there is a missing argument?")
      => Show (a -> b) where
    showsPrec = error "unreachable"

It can also be placed on the right-hand side of a type-level function to provide an error for an invalid case,

type family ByteSize x where
   ByteSize Word16   = 2
   ByteSize Word8    = 1
   ByteSize a        = TypeError (Text "The type " :<>: ShowType a :<>:
                                  Text " is not exportable.")
typetype (<=) (x :: t) (y :: t) = Assert (x <=? y) (LeErrMsg x y)
#

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

datadata Symbol
#

(Kind) This is the kind of type-level symbols.

Instances7SingKind, TestCoercion, TestEquality, SingI, Compare, DemoteRep, …
  • SingKind SymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • TestCoercion SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • TestEquality SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • KnownSymbol a => SingI aDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Compare a b = CmpSymbol a bDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Type.Ord
  • type DemoteRep Symbol = StringDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data SingDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
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.

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

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).

classclass KnownSymbol (n :: Symbol) where
#

This class gives the string associated with a type-level symbol. There are instances of the class for every concrete literal: "hello", etc.

Methods

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.

valuewithSomeSNat :: Integer -> (forall (n :: Nat). Maybe (SNat n) -> r) -> r
#

Attempt to convert an Integer into an SNat n value, where n is a fresh type-level natural number. If the Integer argument is non-negative, invoke the continuation with Just sn, where sn is the SNat n value. If the Integer argument is negative, invoke the continuation with Nothing.

For a version of this function where the continuation uses 'SNat n instead of Maybe (SNat n)@, see withSomeSNat in GHC.TypeNats.

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
newtypenewtype SChar (s :: Char)
#

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

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

  1. The charSing method of KnownChar.

  2. The SChar pattern synonym.

  3. The withSomeSChar function, which creates an SChar from a Char.

Instances5TestCoercion, TestEquality, Eq, Ord, Show
  • TestCoercion SCharDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • TestEquality SCharDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq (SChar c)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord (SChar c)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Show (SChar c)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
patternpattern SChar :: () => KnownChar c => SChar c
#

A explicitly bidirectional pattern synonym relating an SChar to a KnownChar constraint.

As an expression: Constructs an explicit SChar c value from an implicit KnownChar c constraint:

SChar @c :: KnownChar c => SChar c

As a pattern: Matches on an explicit SChar c value bringing an implicit KnownChar c constraint into scope:

f :: SChar c -> ..
f SChar = {- KnownChar c in scope -}
newtypenewtype SSymbol (s :: Symbol)
#

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

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

  1. The symbolSing method of KnownSymbol.

  2. The SSymbol pattern synonym.

  3. The withSomeSSymbol function, which creates an SSymbol from a String.

Instances5TestCoercion, TestEquality, Eq, Ord, Show
  • TestCoercion SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • TestEquality SSymbolDefined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Eq (SSymbol s)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Ord (SSymbol s)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
  • Show (SSymbol s)Defined in ghc-internal-9.1003.0 · GHC.Internal.TypeLits
valuedecideChar
  1. :: (KnownChar a, KnownChar 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 characters, or that the type-level characters are distinct.

datadata SomeChar
#

Constructors

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