functional programming - Haskell add value to tree -
I am trying to create a fun seat that lets me add a new value to a tree if the given path The value is equal to ND (no data), this was my first attempt.
It checks the price etc. But the problem, do I want to print the revised tree with new data? Can anyone give me some signs? I have also tried to create a second function that checks the path to see if the data is OK to add, but how to print the modified tree is lost now?
As iuliux points out, your problem is that you are treating your BT ree as if it were An unstable structure takes the argument to remember the function in Heschel and returns a value. So when you "mapped" a list, or crossed a tree, then your function needs to be returned to a new tree.
The code you have is exceeding the recurring tree and only the last leaf . Imagine that the leaf always be Note that in your original code how do you wipe out Now, on the issue of handling the situation, the address you reach on is not this type of problem Functional Programming is Normal There is a solution for the toughest cases, which is a data structure that gives you, how can you return your recursive data structure to "as you go" Are you As you go up and down, you will please overkill this for your case. I recommend that you change your function to: means that at each level, you will have to return the You should try to understand the implementation for yourself! ND at the end of the path. This is what you want:
add :: a - & gt; Path - & gt; Btree a - & gt; Btree a add da xs ND = Data da add _ [] _ = error "You should make sure that it does not happen or handle it" Da (x: xs) (branch st st2) = Case X of L - gt; Branch (add the xs cents) st2 R - & gt; Branch St. (Add the xs st2) branch "behind you" as it was .
ND constructor:
add :: a - & gt; Path - & gt; Btree a - & gt; It may be that (BTRI A) probably (BTR A) . Then use the funk maybe in the recurring call. Notice:
fmap (+1) (bus 2) == just 3 fmap (+1) (nothing) == nothing
Comments
Post a Comment