3. (a) Convert the following function so that it is tail recursive, and give an expression...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3. (a) Convert the following function so that it is tail recursive, and give an expression to compute the same output as list 10. Give the type of your function. list x = if x==0 then [] else x:list (x-1) In your answer, explain what it means for a function to be tail recursive. (b) Give ONE example of Haskell overloading, and ONE example of Java overloading. Give types of variable/expressions to illustrate your answer. (c) Using the following code, explain the concept of dynamic lookup. class Course ( void describe() { System.out.println("This is a general university course."); } } class MathsCourse extends Course [ void describe() { System.out.println("This is a mathematics course."); } } class History Course extends Course ( void describe() { } System.out.println("This is a history course."); } Write appropriate lines of code to illustrate the concept. To what extent is this related to overloading? (d) Write a function in Haskell called applyA11, which applies a given function to every element of a given list. Show how applyAll can be used to write a function that will produce the same result as this list comprehension: \1 -> [x*x | x <- 1] Your function should take two parameters: a list and a function (in that order). (e) Unification is used in type reconstruction for functional programming (the algorithm was defined in the lecture slides to unify types). The same concept was also used for computation in logic programming, where terms are unified. Explain how unification works in each case, using the following as examples: . The unification of two types: U(A → (D→D). (BC) → A) Show the disagreement pairs at each step. • The evaluation of the Prolog program: add (0, X, X). ?add (A,B, 8 (0)). Draw the SLD tree to show the substitutions. 3. (a) Convert the following function so that it is tail recursive, and give an expression to compute the same output as list 10. Give the type of your function. list x = if x==0 then [] else x:list (x-1) In your answer, explain what it means for a function to be tail recursive. (b) Give ONE example of Haskell overloading, and ONE example of Java overloading. Give types of variable/expressions to illustrate your answer. (c) Using the following code, explain the concept of dynamic lookup. class Course ( void describe() { System.out.println("This is a general university course."); } } class MathsCourse extends Course [ void describe() { System.out.println("This is a mathematics course."); } } class History Course extends Course ( void describe() { } System.out.println("This is a history course."); } Write appropriate lines of code to illustrate the concept. To what extent is this related to overloading? (d) Write a function in Haskell called applyA11, which applies a given function to every element of a given list. Show how applyAll can be used to write a function that will produce the same result as this list comprehension: \1 -> [x*x | x <- 1] Your function should take two parameters: a list and a function (in that order). (e) Unification is used in type reconstruction for functional programming (the algorithm was defined in the lecture slides to unify types). The same concept was also used for computation in logic programming, where terms are unified. Explain how unification works in each case, using the following as examples: . The unification of two types: U(A → (D→D). (BC) → A) Show the disagreement pairs at each step. • The evaluation of the Prolog program: add (0, X, X). ?add (A,B, 8 (0)). Draw the SLD tree to show the substitutions.
Expert Answer:
Answer rating: 100% (QA)
a Convert the following function so that it is tail recursive and give an expression to compute the ... View the full answer
Related Book For
Numerical Methods for Engineers
ISBN: 978-9352602131
7th edition
Authors: Steven C. Chapra, Raymond P. Canale
Posted Date:
Students also viewed these programming questions
-
During the past several months, you downloaded more than 1,000 songs to your portable media player. Tonight, when you turn on your portable media player, it is not able to locate any of your songs...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
To demonstrate the ability to propose, implement, and query the database. Problem: MovinOn Inc. is a moving company that provides moving and storage services in California, Nevada, and Arizona....
-
Codominance observable effect on the phenotype of a heter neither allele is recessive-both alleles are dominant. 6. Which of the genotypes results in a blood type that provides clear evidence of...
-
Early in 2018, a not-for-profit organization received a $4,000,000 gift from a wealthy benefactor. This benefactor specified that the gift be invested in perpetuity with income restricted to provide...
-
What do the circumstances and the holding in this case suggest to a business firm that actively attempts to attract customers in a variety of jurisdictions?
-
Heath has \(\$ 495\) in an account. They will collect two paychecks this week, one for \(\$ 150\) and the other for \(\$ 250\). Heath also will pay three bills, one for \(\$ 50\), one for \(\$ 110\),...
-
You intend to use MUS as a part of the audit of several accounts for Roynpower Manufacturing Company. You have done the audit for the past several years, and there has rarely been an adjusting entry...
-
Lotus Ltd has identified the following overhead costs and costdrivers for next year Overhead Items E ( cost) $ Power 15000Maintenance cost 7800 Ordering cost 6150 Set ups cost 4500 CostDriver E( ac 1...
-
Can you make the journal entries for the transactions below: Dec. 1 - Sold merchandise to Argem Day Care Center for P20,000 and received a 3-month, 12% note. 2 - Purchased merchandise from Stephen...
-
To achieve exactly a 13% rate of return, how much would need to be invested today in an investment which returns $12,000 at the end of 3 years and $10,000 at the end of 5 years? (Round to the nearest...
-
Suppose now that stocks in the XYZ Boat Company are available. These stocks are expected to pay a dividend of $ 7 . 0 0 per share next year. Thereafter, dividend growth is expected to be 5 percent a...
-
The intuitive learning materials worked with my investigation of Section 16, a pivotal segment that tends to different parts of agreement types in the Federal Acquisition Regulation (FAR). This...
-
Apply models and theories of leadership and management to educational settings, describing what this looks like for people, places and practices Trait theory, Socio-cultural theory, and...
-
a) Demonstrate with an example that under perfect market assumptions with no transactions costs or taxes that an equivalent (i) cash dividend and (ii) share repurchase, would leave an investor in the...
-
A tennis ball is hit with a tennis racket and the change in the momentum of the ball is 4.0 kg.m/s. If the collision time of the ball and racket is 0.01 s, what is the magnitude of the force exerted...
-
Business Solutions's second-quarter 2022 fixed budget performance report for its computer furniture operations follows. The $188,130 budgeted expenses include $126,990 in variable expenses for desks...
-
In Exercises 105108, evaluate each expression without using a calculator. log(ln e)
-
Use Gauss elimination to solve: 8x 1 + 2x 2 2x 3 = 22 10x 1 + 2x 2 + 4x 3 = 4 12x 1 + 2x 2 + 2x 3 = 6 Employ partial pivoting and check your answers by substituting them into the original equations.
-
Given the initial conditions, y(0) = 1 and y'(0) = 0, solve the following initial-value problem from t = 0 to 4: d2y/dt2 + 4y = 0 Obtain your solutions with (a) Euler's method and (b) The fourthorder...
-
Solve the following initial value problem over the interval from t = 0 to 2 where y(0) = 1. Display all your results on the same graph. dy /dt = yt2 - 1.1y (a) Analytically. (b) Euler's method with h...
-
Determine if the following sequences are arithmetic sequences. Explain your reasoning. 1. \(\{4,7,10,13,16,19,22,25, \ldots\}\) 2. \(\{20,40,80,160,320,640\}\) 3....
-
As mentioned in the opening to this section, it is estimated that we're producing 2.5 quintillion bytes of data per day. A good estimate is that there are 7.674 billion people on the planet. Convert...
-
Identify \(a_{1}\) and \(d\) for the following arithmetic sequence. Use this information to determine the 60 th term. \[ \{18,31,44,57,70,83, \ldots\} \]
Study smarter with the SolutionInn App