
3 Dec
2007
3 Dec
'07
12:28 a.m.
On Mon, Dec 03, 2007 at 05:20:35AM +0000, PR Stanley wrote:
Hi data Tree = Leaf Int | Node Tree Int Tree
occurs :: Int -> Tree -> Bool occurs m (Leaf n) = m == n occurs m (Node l n r) = m == n || occurs m l || occurs m r
It works but I'd like to know if it can be improved in any way. Thanks, Paul
I'm not sure this will count as improvement, but you can build the same kinds of trees with a simpler datatype: data Tree = Empty | Node Tree Int Tree This way there is only one constructor with the Int value, which can simplify other code a bit. Best regards Tomasz