Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

OCAML psum (fun x -> x * x ) equates to the following function of n. f (n) = 1 * 1 + 2 *

OCAML

psum (fun x -> x * x ) equates to the following function of n.

f (n) = 1 * 1 + 2 * 2 + ... + n * n 

Rules:

  1. We want to always start our index (n) from one, and we allow only positive integers (raise (Failure "Argument Not Positive").
  2. We allow the caller to define what f describes the sum.
  3. We want to return a function (specifically a function awaiting the value of n)

Click for Sample Unit Test

let f x = 3 * x * x + 5 * x + 9 in (** f (x) = 3x^2 + 5x + 9 **) let partial_sum = psum f in if partial_sum 1 = 17 && partial_sum 5 = 285 then print_string "YAY" else raise (Failure "OOPS");

NB: Notice that the type of this function is psum: (int -> int) -> (int -> int) which is to say a function which takes one arguments a function (which takes a int to int) and returns another function (int to int

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Could a project's MIRR ever exceed its IRR?

Answered: 1 week ago