[COMP 302] - Midterm Exam Guide - Ultimate 33 pages long Study Guide!

455 views33 pages

Document Summary

Sum all the numbers from 1 through n. 1 + 2 + 3 + + n. This can easily be written with stuff we already know (using a tail-recursive program that adds them). Let"s allow the user to do it from let rec sumints a b = if (a>b) then 0 else a+sumints(a+1,b) a = lower limit; b = upper limit a to b: This is parametric on the starting value and squares of numbers instead of numbers? the ending value. And why not add let rec sumsquares a b = if (a>b) then 0 else a 2 + sumsquares(a+1,b) This isn"t the same code, but it is very similar. In both functions, we are adding some function to a. Why not make the function we are applying to a, a parameter?? let rec sum(f, a, b) = if (a>b) then 0 else f(a) + sum(f, a+1, b)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents