-
Notifications
You must be signed in to change notification settings - Fork 12
TdE 20170705 #9
Comments
In my understanding of the exercise, and I quote the exercise text, reversing a tree means
and not having a tree which is symmetrical to the input one. Therefore, I believe that |
I agree with @leonardoarcari , i think Nil has no value, is a nullary data constructor and it should stay where it is. If you check the example, the returned tree is isomorphic to the input one, and only the values are Moreover, in 1.3 there's no mention of it. Did you try the proposed solution? |
yes of course,
this was executed with the proposed solution. With the proposed solution t3 reversed is not isomorphic anymore...but probably my definition of isomorphism is wrong because it takes into account Values and Nil as well. Anyways, it appears I was making the problem more difficult than what it was. |
In class we saw this exercise taken from the above mentioned exam
we solved it this way
Unless I understood something wrong, the revtree of a tree like
should be
while the above solution gives
and this is because in revtree' whenever we pattern match a (Nil,xs) we substitute it with (Nil,xs)
which doesn't work when the Nil is not in a symmetrical position.
how can we solve this issue?
It would suffice to write down Nil in our list given by tfringe whenever it is matched (and not []), but Nil is of type Tree, not of type a and the compiler gives an error on types when trying to build a list of a
I remember it being addressed in class but missed the answer.
Any help would be appreciated, Thanks.
The text was updated successfully, but these errors were encountered: