[Haskell-beginners] Questions About Rose Trees Analysis

Henk-Jan van Tuyl hjgtuyl at chello.nl
Thu Dec 17 11:10:01 UTC 2015


On Thu, 17 Dec 2015 11:37:24 +0100, Lorenzo Isella  
<lorenzo.isella at gmail.com> wrote:
:
>
> 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.
:

Your definition of children is correct, what is the message you get from  
the compiler/interpreter?

Regards,
Henk-Jan van Tuyl


-- 
Folding at home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/


http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--


More information about the Beginners mailing list