Why does addition, subtraction and division of Nat
s 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’
Read the word problems and find the product. Apply long multiplication (also known as column multiplication) method for easy calculation. Our engaging theme-based pdf worksheets help young minds understand the fundamentals of multiplication. Answer the word problems based on three fascinating themes - Winter Season, Ice rink and Library.
The word problems featured here are based on practical applications and fact-based situations. Multiply a three or four-digit number by a single-digit multiplier to find the correct product. Sharpen your skills by solving these engaging multi-digit word problems. Apply long multiplication method to solve the problems.
After going through this module, you are expected to solve routine and non routine problems involving multiplication without or with addition or subtraction of decimals and whole numbers including money using appropriate problem-solving strategies and tools.
The *
was used to specify a simple Type
. As a result 1
is seen as something that takes as first type parameter a *
(so Type
) and as second type parameter a 2
, and thus 1
should have kind * -> Nat -> something
. GHC will parse an asterisk (*
) as a reference to Type
if the StarIsType
extension is enabled, which is the default.
If you disable it, then the asterisk (*
) will refer to the multiplication, for example:
Prelude> :set -XDataKinds
Prelude> :set -XTypeOperators
Prelude> :set -XNoStarIsType
Prelude> import GHC.TypeLits
Prelude GHC.TypeLits> :k 1 * 2
1 * 2 :: Nat
Prelude GHC.TypeLits> :kind! 1 * 2
1 * 2 :: Nat
= 2
You can also explicitly specify the module where you use the *
type family family from with:
Prelude> :set -XDataKinds
Prelude> :set -XTypeOperators
Prelude> import GHC.TypeLits
Prelude GHC.TypeLits> :k 1 GHC.TypeLits.* 2
1 GHC.TypeLits.* 2 :: Nat
Prelude GHC.TypeLits> :kind! 1 GHC.TypeLits.* 2
1 GHC.TypeLits.* 2 :: Nat
= 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With