And I have sent the email before it was finished, oops.

Evaluating at integer values works fine, but trying to do
*Main> let a = [-1,2,-6,2]
*Main> horner a 1.23

gives this error

<interactive>:4:10:
    No instance for (Fractional Integer)
      arising from the literal `1.23'
    Possible fix: add an instance declaration for (Fractional Integer)
    In the second argument of `horner', namely `1.23'
    In the expression: horner a 1.23
    In an equation for `it': it = horner a 1.23


I know it has something to do with types, but whenever I try to add a type signature to the functions it just messes everything up even more. Any help would be appreciated

Thanks,
Andrew



On Fri, Dec 13, 2013 at 4:03 PM, Andrew Fleckenstein <andrew.fleckenstein@gmail.com> wrote:
Hi all,

I have implemented Horner's method for evaluating a polynomial as follows:

-- the nth horner element, given a list of coefficients and a value at which it needs to be evaluated

horner_element l x n
    | n == (length l)-1 = last l
    | otherwise = (l !! n) + (horner_element l x (n+1))*x

-- compute a polynomial given as a list of coefficients at the value x using horner's method.

horner l x = horner_element l x 0