Comments (3)
In my understanding of the exercise, and I quote the exercise text, reversing a tree means
“reversing” all the values in the leaves
and not having a tree which is symmetrical to the input one.
Therefore, I believe that Nil
should not be taken into account. Nil
in my opinion stands for there's no branch here, it shouldn't be considered as a value.
So the solution should be correct as, by construction, all the leaves' values appear in reverse order.
from ppl.
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
reversed.
Moreover, in 1.3 there's no mention of it. Did you try the proposed solution?
from ppl.
yes of course,
Unless I understood something wrong, the revtree of a tree like
let t3 = (Branch (Branch (Leaf 3) (Leaf 4)) (Branch Nil (Leaf 5)))
should be
(Branch (Branch (Leaf 5) Nil) (Branch (Leaf 4) (Leaf 3)))
while the above solution gives
Branch (Branch (Leaf 5) (Leaf 4)) (Branch Nil (Leaf 3))
this was executed with the proposed solution.
It's only that, in my mind,when i tried reversing t3 as mentioned I treated Nil as a value and swapped it around as well (on paper).
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.
Thanks!
from ppl.
Related Issues (12)
- change repository name to PPL
- Use tags to archive course material
- use issue to catch student questions
- exercise on continuations (from previous course) HOT 7
- Pattern matching and data types
- Did I get this right? HOT 1
- Exercise on continuations from 20170720 exam HOT 1
- [LAST ERLANG CLASS] Easier brancy? HOT 5
- Reasoning on State monad and unwrapping of do notation
- BLACK JACK WITH COROUTINES, TRY-CATCH AND STRUCTS HOT 1
- Soluzioni tema d'esame 8.2.2019
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ppl.