Hacker News new | ask | show | jobs
by rzzzt 2850 days ago
Evaluation also becomes easy this way, using Horner's method: https://en.wikipedia.org/wiki/Horner%27s_method#Python_imple...
2 comments

Something along the lines of this right?

  eval =
  v [] => 0
  v x:xs => x + v * eval v xs
You do have to love how clean definition by cases makes these sorts of things.
But this doesn't argue for the low-to-high order, because of reversed(). This code would be simpler and faster with the coefficients in the opposite order.
You're right, the process does start from the higher coefficients, and so does not really support the ordering presented.

You either need to use foldr to defer the multiply-and-add until the end of the list is processed, or reverse the list before processing it.