logo CodeStepByStep logo


Language/Type: ML

Define a function named sum_to that accepts an integer parameter n, where sum_to(n) returns: 1 + 1/2 + 1/3 + 1/4 + ... + 1/n .

For example, the call of sum_to(3) should return 1 + 1/2 + 1/3 = 1.83333.... You should return 0.0 if n is 0. You may assume that the function is not passed a negative value of n.

Your function must have the following signature:

val sum_to = fn : int -> real
Type your ML solution code here:

This is a function exercise. Write a ML function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.