Proposal:
=========
The `type select` statement should be removed in favor of `select x.type`,
which works today and provides nearly the same functionality.


Rationale:
=========
- The `type select` statement is basically redundant. For example:

var x = 5;
type select x {
  when int do writeln("int");
  when real do writeln("real");
}

can instead be written as:

var x = 5;
select x.type {
  when int do writeln("int");
  when real do writeln("real");
}

This works in 1.10.0, and maybe in earlier releases.

- Due to a bug in the current implementation of `type select`,
there can be only one `type select` statement in a given scope.


Caveats:
========
- The behavior of the two statements isn't identical.
`type select` uses the function resolution mechanism to choose the
matching `when` clause, while `select` uses the equality operator (==).
For example:

var x: bool = true;
type select x {
  when int do writeln("int");
  otherwise writeln("other");
}

This will print "int", because a variable of type `bool` can be implicitly
converted to an `int`, following the function resolution rules.

On the other hand, the `select x.type` variant:

select x.type {
  when int do writeln("int");
  otherwise writeln("other");
}

will print "other", because x.type is `bool`, and `bool == int` evaluates
to false.

The `type select` behavior can be achieved using functions. For example:

proc f(a: int) { writeln("int"); }
proc f(a) { writeln("other"); }
f(x);

or via some hypothetical future type-coercion introspection abilities:
if isImplicitlyConvertibleToInt(x) then writeln("int") else
writeln("other");

Plan:
=====
If there are no major objections to this proposal, `type select` will
become a syntax error in the next release of chapel (with an error message
suggesting `select .type`). In the following release, the parser won't
recognize `type select`, and will generate a generic syntax error.

Does anyone have any arguments against removing `type select`?
Are there any use-cases that `type select` covers that can't
be handled another way?

Thanks,
Sean
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to