Why doesn\'t the following code doesn\'t work?
fun sum_list xs =
case xs of
[] => NONE
| x::xs\' => SOME (x+sum_list xs\')
This
The problem is that the function is made to return an 'a option
but in the lat expression you use it as if it returned an int:
x + sum_list xs'
You have to either build an internal function that works solely in lists and return numbers (not options), and then box the final result into an option, or eval the result of sum_list
when returned to see if it contains a value or it is NONE
. I can write both ways, but you should try before seeing the solution written.