
20 Dec
2015
20 Dec
'15
7:59 p.m.
Dear All, This is where I stand now. Please consider the short snippet data Rose a = a :> [Rose a] deriving (Eq, Show) root (a :> rs) = a children (a :> rs) = rs size :: Rose a -> Int size (a :> rs) = 1 + (length $ children (a :> rs)) which defines a rose tree structure and the functions to get the root, the children and the size (i.e. number of nodes) of the rose tree. I would like to find the number of leaves (i.e. terminal nodes) in my rose tree. Essentially, I need to count the number of "[]" inside my rose tree definition. For instance, consider mytree = (1 :> [2 :> [], 3 :> []]) which has exactly two leaves. Can anyone help me implement a function to get the number of leaves? Many thanks Lorenzo