[Haskell-cafe] Possible Improvements

Don Stewart dons at galois.com
Mon Dec 3 00:23:30 EST 2007


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


More information about the Haskell-Cafe mailing list