Question
Recall the definition of the nat_num data type seen in class: type nat_num = | Z | S of nat_num ;; And recall the definition
Recall the definition of the nat_num data type seen in class: type nat_num = | Z | S of nat_num ;; And recall the definition of the recursive addition function on nat_nums: let rec add_nn mm nn = match nn with | Z -> mm | S(kk) -> S(add_nn mm kk);; (1) Define a similar multiplication function on nat_nums. Call the function mult_nn. As above, define your function by pattern matching on the second input, nn. In the base case, what should the answer be (when you multiply mm by zero)? In the recursive case, the product of mm and S(kk) can be evaluated by *adding* mm to the product of mm and kk. Once your function is defined, you can test it using expressions such as: # mult_nn (S(S(Z))) (S(S(S(Z))));; - : nat_num = S (S (S (S (S (S Z)))))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started