% $Id: FoldRExamples.oz,v 1.2 2008/01/05 20:01:28 leavens Exp leavens $ %% Examples of the use of FoldR declare % FoldR is built in to the library in Oz fun {FoldR Ls Op Z} case Ls of E|Es then {Op E {FoldR Es Op Z}} else Z end end % Add the elements of Ls fun {Sum Ls} {FoldR Ls fun {$ X Y} X+Y end 0} end % Multiply the elements of Ls fun {Product Ls} {FoldR Ls Number.'*' 1} end % Concatenate the elements of Ls fun {Concat LLs} {FoldR LLs fun {$ X Y} {Append X Y} end nil} end