Define a function, trinum, that returns a stream (infinite list) representing the triangular numbers, which is...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Define a function, trinum, that returns a stream ("infinite list") representing the triangular numbers, which is the sequence 1,3,6,10,15,21,28,.... Note that the difference between numbers increases by one, i.e., 3 = 1+2, 6 = 3 + 3, so in general, tn+1 = tn + n+1 (starting with t₁ = 1). As a reminder, here is our definition for the stream datatype: datatype 'a stream Nil | Cons of 'a (unit> 'a stream); Here is a sample execution, using our printStrm function: val f trinum(); val f - Cons (1, fn): int stream printStrm 10 f; - 1 3 6 10 15 21 M 28 36 45 55 You don't need to know about the implementation of printStrm, nor any other stream functions: you just need to know about Cons and fn in your definition of trinum). You will want a nested function definition inside of trinum, like you did with fib in the homework. Define a function, trinum, that returns a stream ("infinite list") representing the triangular numbers, which is the sequence 1,3,6,10,15,21,28,.... Note that the difference between numbers increases by one, i.e., 3 = 1+2, 6 = 3 + 3, so in general, tn+1 = tn + n+1 (starting with t₁ = 1). As a reminder, here is our definition for the stream datatype: datatype 'a stream Nil | Cons of 'a (unit> 'a stream); Here is a sample execution, using our printStrm function: val f trinum(); val f - Cons (1, fn): int stream printStrm 10 f; - 1 3 6 10 15 21 M 28 36 45 55 You don't need to know about the implementation of printStrm, nor any other stream functions: you just need to know about Cons and fn in your definition of trinum). You will want a nested function definition inside of trinum, like you did with fib in the homework.
Expert Answer:
Answer rating: 100% (QA)
Heres a definition of the trinum function in Standard ML using the provided stream datatype s... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
If the focal length of a lens is 3 centimeters and the image distance is 5 centimeters from the lens, what is the distance from the object to the lens?
-
1. Jowel, the financial manager for Berjayasama Bhd, wishes to evaluate three potential investments: Investment A, Investments B and Investment C. Table 1 shows the expected returns. You have been...
-
In a movie theater in winter, 500 people, each generating sensible heat at a rate of 70 W, are watching a movie. The heat losses through the walls, windows, and the roof are estimated to be 130,000...
-
Salicylic acid, C6H4OHCOOH, is used in the manufacture of acetylsalicylic acid (aspirin) and methyl salicylate (wintergreen flavor). A saturated solution of salicylic acid contains 2.2 g of the acid...
-
Pick an industry and a product or service. Engage in a creative-thinking process, as outlined in Chapter 11, to generate an improved offering. Do the same to create an entirely new offering that uses...
-
The comparative statements of Osborne Company are presented here. All sales were on account. Net cash provided by operating activities for 2014 was $220,000. Capital expenditures were $136,000, and...
-
Why socialism or communism doesn't work in Russia but does in China? as in other countries that we see today. What do you think was the cause of the end of socialism or communism?
-
Brian and Corrine Lee are married taxpayers filing jointly. They live in the home they own, located at 3301 Pacific Coast Hwy., Laguna Beach, CA 92651. Brian is an optometrist who owns his business;...
-
Consider the following class definitions: class A: def ( self , par = 2 : print ( " / b a r ( A ) , end = " " ) print ( par ) if par is not None else print ( 2 ) par = 2 class B ( A ) : def injt (...
-
Under the temporal method, cost of goods sold (COGS) in foreign currency (FC) is translated into parent company currency by Multiple choice question. multiplying COGS in FC by the end-of-period...
-
What did you think of your practicum? Has it prepared you for the working world?
-
Why Recruiting OR Retaining is more important for the organizations? discuss
-
Method number 1. Include each product's traceable fixed costs and an allocated share of the common fixed costs in the numerator of each break-even calculation. The common fixed costs would be...
-
Discuss the major benefits of implementing a succession management process
-
Veronica dies and the life insurance claim becomes subject to further investigation, a coroner's autopsy, and a toxicology report. Which of the following BEST describes the circumstances where these...
-
Why are stocks usually more risky than bonds?
-
Repeat Programming Project 8 in Chapter 1, but add yes-or-no dialogs to allow the user to make the following color changes: Change the color of the solid center circle from black to red. Change the...
-
Write some code that will use an iterator to duplicate every item in an instance of StringLinkedListWithIterator in Listing 12.9. For example, if the list contains "a", "b", and "c", after the code...
-
Define the following methods for the class Ledger, as described in the previous exercise: getAverageSale()returns the average value of all the sales getCountAbove(v)returns the number of sales that...
-
Find the state vector via the formal-solution approach. \(\dot{\mathbf{x}}=\left[\begin{array}{cc}5 & 1 \\ -4 & 1\end{array} ight] \mathbf{x}+\left[\begin{array}{c}1 \\ -1\end{array} ight] u, \quad...
-
A nonlinear dynamic system is described by a. Use the Simulink model to plot x 2 ( t ) x 2 ( t ) . b. Derive the linearized model analytically, build its Simulink model where the linear model is...
-
Consider the mechanical system in Figure 8.28. Assuming \(m=12 \mathrm{~kg}\), \(b=20 \mathrm{~N}\)-sec \(/ \mathrm{m}, k=200 \mathrm{~N} / \mathrm{m}, F_{0}=47 \mathrm{~N}\), and \(\omega=5...
Study smarter with the SolutionInn App