[Haskell-beginners] Questions About Rose Trees Analysis
Lorenzo Isella
lorenzo.isella at gmail.com
Thu Dec 17 10:37:24 UTC 2015
Dear All,
I am trying to learn Haskell (for the second time), but I have to
admit I am still struggling with relative simple stuff, so I ask if
anybody can give me a hand.
I am dealing with the issues of extracting info out of some rose trees
and probably I am also having some troubles with the notation.
The rose tree is defined with the following notation
data Rose a = a :> [Rose a]
deriving (Eq, Show)
and the root can be detected simply as
root (a :> rs) = a
I would like to have the expression (with the ":>" notation for the
Node) of the function to find the children of the root. Example of
expected behavior of this function children
children (1 :> [2 :> [], 3 :> []]) = [2 :> [], 3 :> []]
On top of that, I am trying to get the functions to have the functions
size :: Rose a -> Int
leaves :: Rose a -> Int
that count the number of nodes in a rose tree, respectively the number
of leaves (nodes without any children).
For the children function, I have tried stuff like
children (a :> rs) = rs
quite unsuccessfully.
Any suggestion is appreciated.
Cheers
Lorenzo
More information about the Beginners
mailing list