Why does addition, subtraction and division of Nats work, but not multiplication?
λ> :set -XDataKinds
λ> :set -XTypeOperators
λ> import GHC.TypeLits
λ> :k! 1 + 2
1 + 2 :: Nat
= 3
λ> :k! 1 - 2
1 - 2 :: Nat
= 1 - 2
λ> :k! 5 `Div` 2
5 `Div` 2 :: Nat
= 2
λ> :k! 1 * 2
<interactive>:1:1: error:
• Expected kind ‘* -> Nat -> k0’, but ‘1’ has kind ‘Nat’
• In the type ‘1 * 2’
The
*was used to specify a simpleType. As a result1is seen as something that takes as first type parameter a*(soType) and as second type parameter a2, and thus1should have kind* -> Nat -> something. GHC will parse an asterisk (*) as a reference toTypeif theStarIsTypeextension is enabled, which is the default.If you disable it, then the asterisk (
*) will refer to the multiplication, for example:You can also explicitly specify the module where you use the
*type family family from with: