If you find yourself repeatedly programming a template, you need to record a higher-order function to encapsulate this template. You can use the body that you have, but in order to be absolutely sure that your code does not stand out, I would recommend using foldl and a strict application of the increment operator:
numberSatisfying :: Integral n => (a -> Bool) -> [a] -> n numberSatisfying p = foldl (\nx -> if px then (+1) $! n else n) 0
I used QuickCheck to validate this code equivalent to your source code. (And yes, it's pretty cool that QuickCheck will check with random predicates.)
source share