Possible Duplicate:
Partial sum in Standard ML?
Im new to functional programming and I have an assignment to compute partial sum of a list. E.g. - psum [1,1,1,1,1]; val it = [1,2,3,4,5] : int list
Here is the my code so far. However my function just returns the list as it is.
fun ppsum2([])=[]
| ppsum2(x::L) = x::ppsum2(L);
exception Empty_List;
fun psum(L) : int list =
if L=nil then raise Empty_List
else psum2(L);
psum([2,3,4]);
[] -> []to avoid exceptions entirely. Then, consider the base case and the termination case for the recursive function, and what the result for each step should be, given the input.+at all. Try evaluatingppsum2 [2,3,4]by hand on paper and you'll see why you get an identical list back.