Com S 641 meeting -*- Outline -*- * Other Varieties of parameters (Schmidt 3.4) Q: Besides expression parameters, what other kinds might we have? numerals, commands, declarations, locations, ... ------------------------------------------ OTHER KINDS OF PARAMETERS (3.4) Command and numeral parameters: const K = 2; var A:newint; proc P(M:comm) = (A:=K+1; call M); proc Q(X:int) = A := X in call P(call Q(2)); call P(call P(call Q(K))); call P(A:= K) ------------------------------------------ Q: What should the evaluation mechanism for numeral parameters be? doesn't matter... Q: What about command parameters? lazy is standard What would eagar be like? would give you a store, that you could use or not! backtrack to a saved snapshot of the store How would you implement that? ** declaration parameters ------------------------------------------ DECLARATION PARAMETERS Can be useful in modules: module COUNTER(M:{X: int loc, INIT: comm} dec) = { import M; proc P = (call INIT; X := @X+1) } module N = {var X: newint; proc INIT = X := 0 } import COUNTER(import N) What I want in Haskell: module TypeHelpers(A:{attrib:...} dec) = { proc rule = ... }; module Attributes = {type attrib = ...}; import TypeHelpers(import Attributes); ------------------------------------------ Q: What's a module with a declaration parameter like in ML? a "functor" Q: Do we need to have the argument to COUNTER in a module? Q: Would declaration parameters be useful for other kinds of abstractions besides declaration abstractions (modules)? maybe to type structures (could put them in records...) ------------------------------------------ VARIABLE PARAMETERS Simple ones: var A: newint; proc P(B:int loc) = A := @A + @B; var X:newint in A := 541; X := 641; P(X) Record variables: class K = record var A: newint; proc P(B:int loc) = A:=@A+@B end; var R: K; proc Q(Y: {A:int loc, P: int loc -> comm}) = call Y.P(Y.A) in R.A := 0; call Q(R) ------------------------------------------ Q: What about P(3)? Should that be ok? need a location... Q: Should we use lazy or eager semantics? Are they the same? Q: The type of Y is wordy. Should we write Y:K? no, K is a class, not a record. Q: What else could we do? introduce abstractions for type attributes. type KT = {A:int loc, P: int loc -> comm} Q: How should record types be compared? see the next bit...