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
icon
Related questions
Question

in Haskell, question 4

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.
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
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
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
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning