[eeps] Multi-Parameter Typechecking BIFs

Richard O'Keefe <>
Thu Feb 19 00:22:18 CET 2009


On 19 Feb 2009, at 7:30 am, James Hague wrote:
[an EEP suggesting that is_T(X1, ..., Xn) in a guard should
  have the same meaning as is_T(X1), ..., is_T(Xn).]

This is a straightforward source-to-source transformation
implementable entirely in the compiler front end, with no
back end consequences whatever.

I'm a little unhappy with the grammar of it:
	X1 and ... and Xn is T?
Shouldn't that be are_T(., ...)?

However, may I respectfully suggest that this is yet
ANOTHER problem that is better handled by abstract patterns?

	#vec3(X, Y, Z) when is_float(X), is_float(Y), is_float(Z) ->
	    {X, Y, Z}.

	cross(#vec3(V10,V11,V12), #vec3(V20,V21,V22)) ->
	    #vec3(V11*V22-V12*V21,
		  V12*V20-V10*V22,
		  V10*V21-V11*V20).

Using multi-parameter type tests saves a few calls to
is_float, but you still have to write one call.
Using abstract patterns, the entire guard disappears completely.




More information about the eeps mailing list