declare % Sum: }: Int> fun {Sum Ls} case Ls of E|Es then E+{Sum Es} else 0 end end % Product: }: Int> fun {Product Ls} case Ls of E|Es then E*{Product Es} else 1 end end declare % FoldR: S}: S> fun {FoldR Ls Op Z} case Ls of E|Es then {Op E {FoldR Es Op Z}} else Z end end fun {Product Ls} {FoldR Ls fun {$ E RecursiveResult} E*RecursiveResult end 1} end fun {Sum Ls} {FoldR Ls Number.'+' 0} end % {FoldR (1|(2|(3|nil))) Number.'-' 0} % = 1-(2-(3-0)) % % '|'( 1 '|'( 2 '|'( 3 nil))) % {Number.'-' 1 {Number.'-' 2 {Number.'-' 3 0}}} fun {Concat Ls} {FoldR Ls Append nil} end fun {All Ls} {FoldR Ls fun {$ E Ans} E andthen Ans end true} end