In the for loop you do s:=s+a[i]
but i is set to one of the values in a already - not the index of a value. A first pass fix would be to just change the statement above to s:=s+i
.
You could also write the function as
proc(a::list,b::integer)::integer;
convert(a,`+`)*b;
end;