%%% %%% Static and dynamic typing %%% % dynamically typed languages allow the definition of generic % procedures, e.g., the identity combinator: declare fun {Id X} X end {Browse {Id 5}} {Browse {Id Id}} % however, dynamically typed languages cannot detect some program % errors at compile time, e.g.: declare fun {ShiftRight L} 0|L end {Browse {ShiftRight 4}} % unintended missuse {Browse {ShiftRight [4]}} % proper use %%% %%% Encapsulated stateful ADT %%% declare fun {NewCounter I} S = {NewCell I} proc {Inc} S := @S + 1 end proc {Dec} S := @S - 1 end fun {Get} @S end proc {Put I} S := I end proc {Display} {Browse @S} end in o(inc:Inc dec:Dec get:Get put:Put display:Display) end declare C1 C2 C1 = {NewCounter 0} C2 = {NewCounter 100} {C1.inc} {C1.display} {C2.dec} {C2.display}