4. Make sure that your trees (both general and binary) are instances of Show, Eq, and Ord. The Ord and Eq instantiation should implement a custom ordering, as follows: For some trees t and u we have t≤u iff traces t C traces u t == u iff traces t C traces u and traces u C traces t Pay attention to the fact that you are thus defining a partial order over trees (that is, two trees may not be comparable with each other). 2 Implementation note If you have a type with a parameter (such the type Tree a for trees holding values of type a) it is often the case that the "big" type (Tree a) can be an instance of some class (say, Eq) only if the "inner" type (a) is an instance of a certain type class (say, Ord). This kind of constraints must be specified at instantiation time. In the example mentioned above the instance Tree a of Eq will thus go as follows: instance Ord a => Eq (Tree a) where Note that I used Eq and Ord merely as examples, I am not claiming that the particular example above makes actual sense.
4. Make sure that your trees (both general and binary) are instances of Show, Eq, and Ord. The Ord and Eq instantiation should implement a custom ordering, as follows: For some trees t and u we have t≤u iff traces t C traces u t == u iff traces t C traces u and traces u C traces t Pay attention to the fact that you are thus defining a partial order over trees (that is, two trees may not be comparable with each other). 2 Implementation note If you have a type with a parameter (such the type Tree a for trees holding values of type a) it is often the case that the "big" type (Tree a) can be an instance of some class (say, Eq) only if the "inner" type (a) is an instance of a certain type class (say, Ord). This kind of constraints must be specified at instantiation time. In the example mentioned above the instance Tree a of Eq will thus go as follows: instance Ord a => Eq (Tree a) where Note that I used Eq and Ord merely as examples, I am not claiming that the particular example above makes actual sense.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 9PE
Related questions
Question
in Haskell, question 4

Transcribed Image Text:4. Make sure that your trees (both general and binary) are instances of Show, Eq, and Ord. The
Ord and Eq instantiation should implement a custom ordering, as follows: For some trees t
and u we have
t≤u iff traces t C traces u
t == u iff traces t C traces u and traces u C traces t
Pay attention to the fact that you are thus defining a partial order over trees (that is, two
trees may not be comparable with each other).
2
Implementation note
If you have a type with a parameter (such the type Tree a for trees holding values of type a) it
is often the case that the "big" type (Tree a) can be an instance of some class (say, Eq) only if the
"inner" type (a) is an instance of a certain type class (say, Ord). This kind of constraints must be
specified at instantiation time. In the example mentioned above the instance Tree a of Eq will
thus go as follows:
instance Ord a => Eq (Tree a) where
Note that I used Eq and Ord merely as examples, I am not claiming that the particular example
above makes actual sense.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Recommended textbooks for you

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning

Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
