
I am writing some code to find peaks in molecular spectra. I represent a
spectrum as a list of numbers (intensities) and build a binary search tree
of the positions in the list (x-values) sorted by intensity.
Peaks in the spectrum appear as branches of the tree. My task is to return
branches of a binary tree that contain no other branches larger than some
size.
I wrote this function to test whether a tree can be classified as a peak.
I suspect it's very inefficient, and it doesn't seem idiomatic to me
either. I'm looking for suggestions to improve it:
-- |Returns True if the tree can be classified as a peak. Peaks are
-- qualified by not having any two branches with a size greater than n.
isPeak :: Int -> Tree a -> Bool
isPeak _ Tip = True
isPeak n (Node _ l r)
| (ltn l) && (ltn r) = True
| (ltn l) && (gtn r) = isPeak n r
| (gtn l) && (ltn r) = isPeak n l
| (gtn l) && (gtn r) = False
| otherwise = error "isPeak: no matching condition in guard"
where gtn = (>=n) . size
ltn = (