Haskell’s parameter passing mechanism is an implementation of Pass-by-Name. It can also be said that Haskell is an implementation of Pass-by-Need (i.e. parameters are analyzed on an as-needed basis). Explain the advantages of this parameter passing strategy and give an example using code.
InIpass by name mechanismn pass the symbolic "name"; of a variable, which allows it both to be accessed and updated.
In the following example, to double the value of C[j], we pass its name (not its value) into the following procedure.
procedure double(x); real x; begin x := x * 2 end;
The effect of pass-by-name is to textually substitute the argument expressions in a procedure call for the corresponding parameters in the body of the procedure, e.g., double(C[j]) is interpreted as C[j] := C[j] * 2. If any of the variables in the called procedure clash with the caller's variables, they must be renamed uniquely before substitution.
Advantages of the pass-by-name mechanism:
Get Answers For Free
Most questions answered within 1 hours.