(* * Cf. ./sum-list.rsl. Getting more twinges that multiple inheritance a la * Java interfaces subsumes OBJ-style theories and views. *) object SummableList = SummableObject*; object SummableObject = i:integer or r:real; (* * The need for this version of Sum, as opposed to just being able to use * built-in '+', is I believe obviatelable if we define '+' properly by putting * it's sig in the Level 0 symtab rather than typechecking its args as a * special case. *) op Sum(x:SummableObject, y:SummableObject) -> real = if (x?.i) and (y?.i) then x.i + y.i else if (x?.i) and (y?.r) then x.i + y.r else if (x?.r) and (y?.i) then x.r + y.i else x.r + y.r; function SumList(sl:SummableList)->real = if sl = nil then 0 else sl[1] + SumList(sl[2:#sl]); -- ERROR in V3, per earlier comment -- above definition of function Sum -- !! FIXED 3dec09. See CVS log and admin/LOG entries of this date. function SumList2(sl:SummableList)->real = if sl = nil then 0 else Sum(sl[1], SumList(sl[2:#sl])); op main() = ( Sum(1,2); Sum("1","2"); -- ERROR, presumably always );