Sml program -> confusion on "AS syntax error"

Solution 1:

It looks like you have a typo. Your second = should be a |.

fun epoly([], x:real) = 0.0
  | epoly(L:real list as h::T, x:real) = 
      h + (x * epoly(T, x));

There is, further, no need to specify types. Your SML compiler can infer the types from data presented. Along with removing unnecessary bindings, this can be reduced to:

fun epoly([], _) = 0.0
  | epoly(h::T, x) = 
      h + (x * epoly(T, x));

From fun epoly([], _) = 0.0 we know epoly will take a tuple of a list and some type and return real.

From:

  | epoly(h::T, x) = 
      h + (x * epoly(T, x));

We know that x is being multiplied by a real, so x must be real. And since h is being added to a real, it must be a real, so the entire list is a real list.

Thus the type of epoly can be inferred correctly to be real list * real -> real.