Declaring Haskell Types

.pdf

School

University of Kansas *

*We aren’t endorsed by this school

Course

368

Subject

Computer Science

Date

Oct 30, 2023

Type

pdf

Pages

1

Uploaded by JusticeHawk30256

Consider the following type of binary trees: data Tree a = Leaf a | Node (Tree a) (Tree a) Let us say that such a tree is balanced if the number of leaves in the left and right subtree of every node di ff ers by at most one. 1. Define a function that returns the number of leaves in a tree: leaves :: Tree a -> Int leaves Leaf a = 1 leaves (Node lhs rhs) = leaves lhs + leaves rhs 2. Use the leaves function, to define a function: balanced :: Tree a -> Bool balanced Leaf _ = True balanced (Node lhs rhs) = leaves lhs - leaves rhs <= 1
Discover more documents: Sign up today!
Unlock a world of knowledge! Explore tailored content for a richer learning experience. Here's what you'll get:
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: How does 2sec(t/2) is equal to 1/2sec(t/2)?
Q: Resonance. For each of the following structural formulas, provide the indicated number of resonance…
Q: octor wants to estimate the mean trigliceride level of all 20- to 29-year-old females (in milligram…
Q: While walking through a busy city park, John experiences sharp chest painsthat indicate to him the…
Q: Assume that C(x) is in dollars and x is the number of units produced and sold. For the total-cost…
Q: A 140-kg rugby player running east with a speed of 4.00 m/s tackles an 87.5-kg opponent running…
Q: The hydraulic cylinder D extends, moves the rigid rod ABC, and causes the r A to move with velocity…
Q: ну-дуу ОН ОН ОН ОН Н ОН OH ОН ОН ОН
Q: spring-loaded toy gun is aimed vertically and fired after a spherical projectile of mass m = 28.0 g…
Q: Can you help me step by step?
Q: 5 y" + y + y = 1-u (t); y(0) = 1, y'(0) = −1 -1
Q: you will write a c++ program to input 5 elements (of type int) from the user and store them in an…
Q: Solve for x in In(x+3)=5. Give an exact answer only. Write "no solution" if necessary. As always, be…
Q: Formal Charges. Add formal charge where appropriate. You are not required to show calculations. ( H…
Q: Velocity (m/s) $ -10 -12 W (a) n Velocity vs. Time W (d) A mass m box starts from rest at the…
Q: Q24. As shown in the image below, the 16-kg block A and the 42-kg block B connected by the…
Q: d) Determine the acceleration the satellite must feel as a function of distance and TS. e) Find…
Q: The height (in ft) of a projectile launched off a cliff over water is given by: h (t) = -16 t2 +…
Q: The air in an inflated balloon (defined as the system) is warmed over a toaster and absorbs 130 J of…
Q: What is the average centripetal acceleration of a car travelling at 20 meters/second on a circular…
Q: Which of the given values is a solution to the equation -8d + 2 = -40d + 2? Select the correct…
Q: Ozone