> How about this:
>
> makeChanges total coins =
>   tail $ map fst $ scanl (\(how_many,rest) -> divMod rest) (0,total) coins

You may want to push it further:

makeChanges total =
  tail . map fst . scanl (divMod . snd) (0,total)

which, IMHO, is a little obfuscated (although some people may think this is
actually easier to understand).  If the reader does not know what divMod does,
the code can be mysterious.  However in your original code, the expression

let (how_many,rest) = divMod n coin_val in ...

is quite self-explanatary.

Higher-orderness, is used unwisely, can be bad.

-- Zhanyong Wan


Reply via email to