Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres a definition of the trinum function in Standard ML using the provided stream datatype s...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