[Haskell-cafe] Possible Improvements

Tim Chevalier catamorphism at gmail.com
Mon Dec 3 00:35:29 EST 2007


On 12/2/07, Don Stewart <dons at galois.com> wrote:
> 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.
>

IMO, there's no reason to even think about putting in the strictness
annotations unless you've identified this datatype as part of a
performance bottleneck in production code. Otherwise, there's no need
to clutter your code and your mind with them :-)

Cheers,
Tim

-- 
Tim Chevalier * catamorphism.org * Often in error, never in doubt
"Base eight is just like base ten, really... if you're missing two
fingers."  -- Tom Lehrer


More information about the Haskell-Cafe mailing list