Writing higher-order functions