Skip to content

Integral

Integral is the class of all integral number types. Instances include Int, Integer, and a whole long list of integral number types defined in Data.Word. While Integral is a subclass of Num—integers are numbers after all—it is not a direct subclass of Num:

GHCi
type Integral :: * -> Constraint
class (Real a, Enum a) => Integral a where
  quot :: a -> a -> a
  rem :: a -> a -> a
  div :: a -> a -> a
  mod :: a -> a -> a
  quotRem :: a -> a -> (a, a)
  divMod :: a -> a -> (a, a)
  toInteger :: a -> Integer
  {-# MINIMAL quotRem, toInteger #-}
    -- Defined in ‘GHC.Real’
[More omitted output]

This says that integral number types need to support the expected integral division operations div and quot, along with the corresponding remainder operations mod and rem, as well as the combinations of division and remainder divMod and quotRem. An integral type, being an integer, should also be convertible back to an Integer, using toInteger.

Now, as I just said, Num is not a direct superclass of Integral: it does not occur in the list of superclasses of Integral at all. The immediate superclasses of Integral are Real and Enum. Real is a direct subclass of Num, so that's how Integral is a class of number types.