Traverse a tree with an arbitrary number of branches





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I want to calculate the maximum degree in a Tree which has an arbitrary number of branches.



data Tree a = Node a [Tree a]
deriving (Eq, Show)

{-

2
/ |
7 3 1
| /
0 3 2
For this case: Answer will be 3.
-}
tree1 :: Tree Int
tree1 = Node 2 [Node 7 , Node 3 [Node 0 ], Node 1 [Node 3 , Node 2 ]]

--I am doing something like this:

maxBranching :: Tree Int -> Int
maxBranching Node n = 1
maxBranching Node n xs = max (length xs) maxBranching xs


Now, I am getting an error. How can I write the correct pattern to solve this problem?










share|improve this question

























  • What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

    – ShamPooSham
    Nov 16 '18 at 15:56











  • • The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

    – RajibTheKing
    Nov 16 '18 at 15:58











  • Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

    – ShamPooSham
    Nov 16 '18 at 16:02











  • Sounds like a job for Foldable?

    – Anthony Raimondo
    Nov 16 '18 at 16:34











  • @AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

    – dfeuer
    Nov 16 '18 at 16:55


















2















I want to calculate the maximum degree in a Tree which has an arbitrary number of branches.



data Tree a = Node a [Tree a]
deriving (Eq, Show)

{-

2
/ |
7 3 1
| /
0 3 2
For this case: Answer will be 3.
-}
tree1 :: Tree Int
tree1 = Node 2 [Node 7 , Node 3 [Node 0 ], Node 1 [Node 3 , Node 2 ]]

--I am doing something like this:

maxBranching :: Tree Int -> Int
maxBranching Node n = 1
maxBranching Node n xs = max (length xs) maxBranching xs


Now, I am getting an error. How can I write the correct pattern to solve this problem?










share|improve this question

























  • What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

    – ShamPooSham
    Nov 16 '18 at 15:56











  • • The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

    – RajibTheKing
    Nov 16 '18 at 15:58











  • Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

    – ShamPooSham
    Nov 16 '18 at 16:02











  • Sounds like a job for Foldable?

    – Anthony Raimondo
    Nov 16 '18 at 16:34











  • @AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

    – dfeuer
    Nov 16 '18 at 16:55














2












2








2








I want to calculate the maximum degree in a Tree which has an arbitrary number of branches.



data Tree a = Node a [Tree a]
deriving (Eq, Show)

{-

2
/ |
7 3 1
| /
0 3 2
For this case: Answer will be 3.
-}
tree1 :: Tree Int
tree1 = Node 2 [Node 7 , Node 3 [Node 0 ], Node 1 [Node 3 , Node 2 ]]

--I am doing something like this:

maxBranching :: Tree Int -> Int
maxBranching Node n = 1
maxBranching Node n xs = max (length xs) maxBranching xs


Now, I am getting an error. How can I write the correct pattern to solve this problem?










share|improve this question
















I want to calculate the maximum degree in a Tree which has an arbitrary number of branches.



data Tree a = Node a [Tree a]
deriving (Eq, Show)

{-

2
/ |
7 3 1
| /
0 3 2
For this case: Answer will be 3.
-}
tree1 :: Tree Int
tree1 = Node 2 [Node 7 , Node 3 [Node 0 ], Node 1 [Node 3 , Node 2 ]]

--I am doing something like this:

maxBranching :: Tree Int -> Int
maxBranching Node n = 1
maxBranching Node n xs = max (length xs) maxBranching xs


Now, I am getting an error. How can I write the correct pattern to solve this problem?







haskell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:30









dfeuer

33.8k349133




33.8k349133










asked Nov 16 '18 at 15:47









RajibTheKingRajibTheKing

628527




628527













  • What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

    – ShamPooSham
    Nov 16 '18 at 15:56











  • • The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

    – RajibTheKing
    Nov 16 '18 at 15:58











  • Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

    – ShamPooSham
    Nov 16 '18 at 16:02











  • Sounds like a job for Foldable?

    – Anthony Raimondo
    Nov 16 '18 at 16:34











  • @AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

    – dfeuer
    Nov 16 '18 at 16:55



















  • What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

    – ShamPooSham
    Nov 16 '18 at 15:56











  • • The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

    – RajibTheKing
    Nov 16 '18 at 15:58











  • Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

    – ShamPooSham
    Nov 16 '18 at 16:02











  • Sounds like a job for Foldable?

    – Anthony Raimondo
    Nov 16 '18 at 16:34











  • @AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

    – dfeuer
    Nov 16 '18 at 16:55

















What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

– ShamPooSham
Nov 16 '18 at 15:56





What error are you getting? I suppose you simply need to put brackets around Node n *, ie (Node n ) and (Node n xs)

– ShamPooSham
Nov 16 '18 at 15:56













• The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

– RajibTheKing
Nov 16 '18 at 15:58





• The constructor ‘Node’ should have 2 arguments, but has been given none • In the pattern: Node In an equation for ‘maxBranching’: maxBranching Node n = 1 The equation(s) for ‘maxBranching’ have three arguments, but its type ‘Tree Int -> Int’ has only one | 22 | maxBranching Node n = 1

– RajibTheKing
Nov 16 '18 at 15:58













Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

– ShamPooSham
Nov 16 '18 at 16:02





Sounds like my suggestion would fix that. Without parentheses around Node n xs, it thinks n and xs are second and third arguments to maxBranching instead of Node

– ShamPooSham
Nov 16 '18 at 16:02













Sounds like a job for Foldable?

– Anthony Raimondo
Nov 16 '18 at 16:34





Sounds like a job for Foldable?

– Anthony Raimondo
Nov 16 '18 at 16:34













@AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

– dfeuer
Nov 16 '18 at 16:55





@AnthonyRaimondo, Foldable isn't actually powerful enough for this job. Foldable effectively flattens out the very tree structure that needs to be examined.

– dfeuer
Nov 16 '18 at 16:55












3 Answers
3






active

oldest

votes


















3














Firstly, the type of parameter of maxBranching is Tree Int and not [Tree Int] and you want to map all Children Nodes to its maximum degrees, so it should be:



map maxBranching xs


Not



maxBranching xs


Secondly, parameter need in parentheses, otherwise, the function maxBranching become accept 3 parameters.



put them all as:



maxBranching :: Tree Int -> Int
maxBranching (Node _ ) = 1
maxBranching (Node _ xs) = maximum $ (length xs) : (map maxBranching xs)





share|improve this answer
























  • Yes, it's working.

    – RajibTheKing
    Nov 16 '18 at 16:41



















3














You want to traverse a tree generating a sort of "summary value". This is a classic example of a catamorphism or fold. The general fold for trees looks like this:



foldTree :: (a -> [b] -> b) -> Tree a -> b
foldTree f (Node a bs) = f a (map (foldTree f) bs)


The idea here is that at each tree node,



Node r [t1,t2,t3]


we first reduce each child recursively to a summary value, then apply the given function and the root value and the summaries of the children to produce a summary for the tree.



Now



maxBranching :: Tree a -> Int
maxBranching = foldTree $
_ bs -> maximum (length bs : bs)


That is, at each node, we take the maximum of the number of branches of that node and each of its children.






share|improve this answer

































    0














    First of all, you need to put parentheses around your argument, like this:



    maxBranching (Node n xs) = ...


    If you don't put parentheses around your arguments, the compiler can't know if n and xs/ belongs to Node or maxBranching.



    Next issue you have is that your recursive call is done on a list of Tree Int instead of just a Tree Int. What you need to do is to get the maxBranching of each subtree and then compare the result to each other. So a first, naive approach, would be the following:



    maxBranching (Node n xs) = max (length xs) (maximum (map maxBranching xs))


    map will run maxBranching on every element of the list xs, returning an array of Int. maximum will then take the max in the list. The difference between max and maximum is that max only takes two arguments and compare them, while maximum takes a list which is arbitrarily long.



    We could get rid of maxby adding length xs into the list we created, and running maximum on everything, like this:



    maxBranching (Node n xs) = maximum $ (length xs):(map maxBranching xs)


    And if you don't know, $ is equvivalent with putting parantheses around the rest of the line (more or less).



    You could also use smart methods as folding and the like, but I just wanted you to understand the errors you did and how to fix them without changing the core idea of your solution.






    share|improve this answer


























    • I tried your solution, but still I am getting error.

      – RajibTheKing
      Nov 16 '18 at 16:41











    • xs is of type [Tree Int] not a Tree Int

      – karakfa
      Nov 16 '18 at 20:00











    • Ah yes, that's an issue too. Let me edit my answer

      – ShamPooSham
      Nov 17 '18 at 9:02












    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341188%2ftraverse-a-tree-with-an-arbitrary-number-of-branches%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Firstly, the type of parameter of maxBranching is Tree Int and not [Tree Int] and you want to map all Children Nodes to its maximum degrees, so it should be:



    map maxBranching xs


    Not



    maxBranching xs


    Secondly, parameter need in parentheses, otherwise, the function maxBranching become accept 3 parameters.



    put them all as:



    maxBranching :: Tree Int -> Int
    maxBranching (Node _ ) = 1
    maxBranching (Node _ xs) = maximum $ (length xs) : (map maxBranching xs)





    share|improve this answer
























    • Yes, it's working.

      – RajibTheKing
      Nov 16 '18 at 16:41
















    3














    Firstly, the type of parameter of maxBranching is Tree Int and not [Tree Int] and you want to map all Children Nodes to its maximum degrees, so it should be:



    map maxBranching xs


    Not



    maxBranching xs


    Secondly, parameter need in parentheses, otherwise, the function maxBranching become accept 3 parameters.



    put them all as:



    maxBranching :: Tree Int -> Int
    maxBranching (Node _ ) = 1
    maxBranching (Node _ xs) = maximum $ (length xs) : (map maxBranching xs)





    share|improve this answer
























    • Yes, it's working.

      – RajibTheKing
      Nov 16 '18 at 16:41














    3












    3








    3







    Firstly, the type of parameter of maxBranching is Tree Int and not [Tree Int] and you want to map all Children Nodes to its maximum degrees, so it should be:



    map maxBranching xs


    Not



    maxBranching xs


    Secondly, parameter need in parentheses, otherwise, the function maxBranching become accept 3 parameters.



    put them all as:



    maxBranching :: Tree Int -> Int
    maxBranching (Node _ ) = 1
    maxBranching (Node _ xs) = maximum $ (length xs) : (map maxBranching xs)





    share|improve this answer













    Firstly, the type of parameter of maxBranching is Tree Int and not [Tree Int] and you want to map all Children Nodes to its maximum degrees, so it should be:



    map maxBranching xs


    Not



    maxBranching xs


    Secondly, parameter need in parentheses, otherwise, the function maxBranching become accept 3 parameters.



    put them all as:



    maxBranching :: Tree Int -> Int
    maxBranching (Node _ ) = 1
    maxBranching (Node _ xs) = maximum $ (length xs) : (map maxBranching xs)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 '18 at 16:26









    assembly.jcassembly.jc

    2,1041215




    2,1041215













    • Yes, it's working.

      – RajibTheKing
      Nov 16 '18 at 16:41



















    • Yes, it's working.

      – RajibTheKing
      Nov 16 '18 at 16:41

















    Yes, it's working.

    – RajibTheKing
    Nov 16 '18 at 16:41





    Yes, it's working.

    – RajibTheKing
    Nov 16 '18 at 16:41













    3














    You want to traverse a tree generating a sort of "summary value". This is a classic example of a catamorphism or fold. The general fold for trees looks like this:



    foldTree :: (a -> [b] -> b) -> Tree a -> b
    foldTree f (Node a bs) = f a (map (foldTree f) bs)


    The idea here is that at each tree node,



    Node r [t1,t2,t3]


    we first reduce each child recursively to a summary value, then apply the given function and the root value and the summaries of the children to produce a summary for the tree.



    Now



    maxBranching :: Tree a -> Int
    maxBranching = foldTree $
    _ bs -> maximum (length bs : bs)


    That is, at each node, we take the maximum of the number of branches of that node and each of its children.






    share|improve this answer






























      3














      You want to traverse a tree generating a sort of "summary value". This is a classic example of a catamorphism or fold. The general fold for trees looks like this:



      foldTree :: (a -> [b] -> b) -> Tree a -> b
      foldTree f (Node a bs) = f a (map (foldTree f) bs)


      The idea here is that at each tree node,



      Node r [t1,t2,t3]


      we first reduce each child recursively to a summary value, then apply the given function and the root value and the summaries of the children to produce a summary for the tree.



      Now



      maxBranching :: Tree a -> Int
      maxBranching = foldTree $
      _ bs -> maximum (length bs : bs)


      That is, at each node, we take the maximum of the number of branches of that node and each of its children.






      share|improve this answer




























        3












        3








        3







        You want to traverse a tree generating a sort of "summary value". This is a classic example of a catamorphism or fold. The general fold for trees looks like this:



        foldTree :: (a -> [b] -> b) -> Tree a -> b
        foldTree f (Node a bs) = f a (map (foldTree f) bs)


        The idea here is that at each tree node,



        Node r [t1,t2,t3]


        we first reduce each child recursively to a summary value, then apply the given function and the root value and the summaries of the children to produce a summary for the tree.



        Now



        maxBranching :: Tree a -> Int
        maxBranching = foldTree $
        _ bs -> maximum (length bs : bs)


        That is, at each node, we take the maximum of the number of branches of that node and each of its children.






        share|improve this answer















        You want to traverse a tree generating a sort of "summary value". This is a classic example of a catamorphism or fold. The general fold for trees looks like this:



        foldTree :: (a -> [b] -> b) -> Tree a -> b
        foldTree f (Node a bs) = f a (map (foldTree f) bs)


        The idea here is that at each tree node,



        Node r [t1,t2,t3]


        we first reduce each child recursively to a summary value, then apply the given function and the root value and the summaries of the children to produce a summary for the tree.



        Now



        maxBranching :: Tree a -> Int
        maxBranching = foldTree $
        _ bs -> maximum (length bs : bs)


        That is, at each node, we take the maximum of the number of branches of that node and each of its children.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 16:52

























        answered Nov 16 '18 at 16:46









        dfeuerdfeuer

        33.8k349133




        33.8k349133























            0














            First of all, you need to put parentheses around your argument, like this:



            maxBranching (Node n xs) = ...


            If you don't put parentheses around your arguments, the compiler can't know if n and xs/ belongs to Node or maxBranching.



            Next issue you have is that your recursive call is done on a list of Tree Int instead of just a Tree Int. What you need to do is to get the maxBranching of each subtree and then compare the result to each other. So a first, naive approach, would be the following:



            maxBranching (Node n xs) = max (length xs) (maximum (map maxBranching xs))


            map will run maxBranching on every element of the list xs, returning an array of Int. maximum will then take the max in the list. The difference between max and maximum is that max only takes two arguments and compare them, while maximum takes a list which is arbitrarily long.



            We could get rid of maxby adding length xs into the list we created, and running maximum on everything, like this:



            maxBranching (Node n xs) = maximum $ (length xs):(map maxBranching xs)


            And if you don't know, $ is equvivalent with putting parantheses around the rest of the line (more or less).



            You could also use smart methods as folding and the like, but I just wanted you to understand the errors you did and how to fix them without changing the core idea of your solution.






            share|improve this answer


























            • I tried your solution, but still I am getting error.

              – RajibTheKing
              Nov 16 '18 at 16:41











            • xs is of type [Tree Int] not a Tree Int

              – karakfa
              Nov 16 '18 at 20:00











            • Ah yes, that's an issue too. Let me edit my answer

              – ShamPooSham
              Nov 17 '18 at 9:02
















            0














            First of all, you need to put parentheses around your argument, like this:



            maxBranching (Node n xs) = ...


            If you don't put parentheses around your arguments, the compiler can't know if n and xs/ belongs to Node or maxBranching.



            Next issue you have is that your recursive call is done on a list of Tree Int instead of just a Tree Int. What you need to do is to get the maxBranching of each subtree and then compare the result to each other. So a first, naive approach, would be the following:



            maxBranching (Node n xs) = max (length xs) (maximum (map maxBranching xs))


            map will run maxBranching on every element of the list xs, returning an array of Int. maximum will then take the max in the list. The difference between max and maximum is that max only takes two arguments and compare them, while maximum takes a list which is arbitrarily long.



            We could get rid of maxby adding length xs into the list we created, and running maximum on everything, like this:



            maxBranching (Node n xs) = maximum $ (length xs):(map maxBranching xs)


            And if you don't know, $ is equvivalent with putting parantheses around the rest of the line (more or less).



            You could also use smart methods as folding and the like, but I just wanted you to understand the errors you did and how to fix them without changing the core idea of your solution.






            share|improve this answer


























            • I tried your solution, but still I am getting error.

              – RajibTheKing
              Nov 16 '18 at 16:41











            • xs is of type [Tree Int] not a Tree Int

              – karakfa
              Nov 16 '18 at 20:00











            • Ah yes, that's an issue too. Let me edit my answer

              – ShamPooSham
              Nov 17 '18 at 9:02














            0












            0








            0







            First of all, you need to put parentheses around your argument, like this:



            maxBranching (Node n xs) = ...


            If you don't put parentheses around your arguments, the compiler can't know if n and xs/ belongs to Node or maxBranching.



            Next issue you have is that your recursive call is done on a list of Tree Int instead of just a Tree Int. What you need to do is to get the maxBranching of each subtree and then compare the result to each other. So a first, naive approach, would be the following:



            maxBranching (Node n xs) = max (length xs) (maximum (map maxBranching xs))


            map will run maxBranching on every element of the list xs, returning an array of Int. maximum will then take the max in the list. The difference between max and maximum is that max only takes two arguments and compare them, while maximum takes a list which is arbitrarily long.



            We could get rid of maxby adding length xs into the list we created, and running maximum on everything, like this:



            maxBranching (Node n xs) = maximum $ (length xs):(map maxBranching xs)


            And if you don't know, $ is equvivalent with putting parantheses around the rest of the line (more or less).



            You could also use smart methods as folding and the like, but I just wanted you to understand the errors you did and how to fix them without changing the core idea of your solution.






            share|improve this answer















            First of all, you need to put parentheses around your argument, like this:



            maxBranching (Node n xs) = ...


            If you don't put parentheses around your arguments, the compiler can't know if n and xs/ belongs to Node or maxBranching.



            Next issue you have is that your recursive call is done on a list of Tree Int instead of just a Tree Int. What you need to do is to get the maxBranching of each subtree and then compare the result to each other. So a first, naive approach, would be the following:



            maxBranching (Node n xs) = max (length xs) (maximum (map maxBranching xs))


            map will run maxBranching on every element of the list xs, returning an array of Int. maximum will then take the max in the list. The difference between max and maximum is that max only takes two arguments and compare them, while maximum takes a list which is arbitrarily long.



            We could get rid of maxby adding length xs into the list we created, and running maximum on everything, like this:



            maxBranching (Node n xs) = maximum $ (length xs):(map maxBranching xs)


            And if you don't know, $ is equvivalent with putting parantheses around the rest of the line (more or less).



            You could also use smart methods as folding and the like, but I just wanted you to understand the errors you did and how to fix them without changing the core idea of your solution.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 17 '18 at 9:31

























            answered Nov 16 '18 at 16:09









            ShamPooShamShamPooSham

            546518




            546518













            • I tried your solution, but still I am getting error.

              – RajibTheKing
              Nov 16 '18 at 16:41











            • xs is of type [Tree Int] not a Tree Int

              – karakfa
              Nov 16 '18 at 20:00











            • Ah yes, that's an issue too. Let me edit my answer

              – ShamPooSham
              Nov 17 '18 at 9:02



















            • I tried your solution, but still I am getting error.

              – RajibTheKing
              Nov 16 '18 at 16:41











            • xs is of type [Tree Int] not a Tree Int

              – karakfa
              Nov 16 '18 at 20:00











            • Ah yes, that's an issue too. Let me edit my answer

              – ShamPooSham
              Nov 17 '18 at 9:02

















            I tried your solution, but still I am getting error.

            – RajibTheKing
            Nov 16 '18 at 16:41





            I tried your solution, but still I am getting error.

            – RajibTheKing
            Nov 16 '18 at 16:41













            xs is of type [Tree Int] not a Tree Int

            – karakfa
            Nov 16 '18 at 20:00





            xs is of type [Tree Int] not a Tree Int

            – karakfa
            Nov 16 '18 at 20:00













            Ah yes, that's an issue too. Let me edit my answer

            – ShamPooSham
            Nov 17 '18 at 9:02





            Ah yes, that's an issue too. Let me edit my answer

            – ShamPooSham
            Nov 17 '18 at 9:02


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53341188%2ftraverse-a-tree-with-an-arbitrary-number-of-branches%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine