[eeps] Multi-Parameter Typechecking BIFs
James Hague
james.hague@REDACTED
Wed Feb 25 05:24:13 CET 2009
A very interesting discussion indeed!
As I see it, we're looking at different levels of changes to Erlang.
If you peruse the Wings 3D vector and matrix math module, it's pretty
clear that the current situation is bulky, to say the least. That's
the kind of code I had in mind when I wrote my proposal--witness all
the 1 and 2 character parameter names. Allowing multiple parameters
to is_float and friends is a dead simple implementation, one that fits
the current Erlang coding style well. I'm not saying it's the BEST
proposal, all things considered, just that it's simple and doesn't
affect the language much.
Now we've got the "::type" syntax, and I agree with Kenneth that it
cuts down on variable name duplication, and it's shorter overall. But
it also makes some patterns harder to read, combining a "picture" of a
structure with the types contained in it. That could potentially
change Erlang coding style for me, because the source code density has
shifted around a bit. It's worth trying to rewrite some existing
modules with this syntax before committing to it.
Then we have Richard's proposal, and I think history will likely prove
him right, But it's clearly a big change in terms of implementation,
otherwise it would have happened already.
Anyhow, here's the example from my EEP, with the "::type" syntax added:
Current:
cross({V10,V11,V12}, {V20,V21,V22}) when is_float(V10),
is_float(V11), is_float(V12),
is_float(V20), is_float(V21), is_float(V22) ->
{V11*V22-V12*V21,V12*V20-V10*V22,V10*V21-V11*V20}.
Multiple parameters;
cross({V10,V11,V12}, {V20,V21,V22}) when
is_float(V10,V11,V12,V20,V21,V22) ->
{V11*V22-V12*V21,V12*V20-V10*V22,V10*V21-V11*V20}.
Inline types:
cross({V10::float,V11::float,V12::float},
{V20::float,V21::float,V22::float}) ->
{V11*V22-V12*V21,V12*V20-V10*V22,V10*V21-V11*V20}.
Purely from this example, I admit to liking inline types, but it's
still so repetitive that I'd probably use a macro:
cross(?vec3(V10,V11,V12), ?vec3(V20,V21,V22)) ->
{V11*V22-V12*V21,V12*V20-V10*V22,V10*V21-V11*V20}.
More information about the eeps
mailing list