CTM: Exercise 3-5

[ Posted by Urban Hafner Wed, 14 Sep 2005 19:24:24 GMT ]

The problem

An iterative SumList. Rewrite the function SumList of section 3.4.2 to be iterative using the techniques developed for Length.

My solution

local
   fun {IterSumList S Es}
      case Es
      of nil then S
      [] E|Er then {IterSumList S+E Er}
      end
   end
in
   fun {SumList L}
      {IterSumList 0 L}
   end
end

Tags , , , , , ,