[back]

Summing Rose Trees

type 'a rtree = Node of 'a * 'a rtree list

Implement the function

val sum : int rtree -> int

so that sum t is the sum of all the elements at the nodes of t.

Examples

let _ = assert (sum (Node (1, [Node (2, []); Node (3, [])])) = 6)
let _ = assert (sum (Node (5, [])) = 5)