
3 Dec
2007
3 Dec
'07
12:23 a.m.
prstanley:
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.
You could probably get away with: data Tree = Leaf !Int | Node Tree !Int Tree but that's a minor issue. I don't see anything wrong this this code -- isn't that what you'd hope to write? -- Don