On 10/06/2014 04:40 AM, monarch_dodra wrote:
On Monday, 6 October 2014 at 11:28:16 UTC, John Colvin wrote:
string a;
char[] b;
pragma(msg, typeof(a ~ b)); // char[]
why not string?
What are the rules that determine this?
*Ideally*, I'd have said "it returns char[], so that you can chose via
purity".
However, it's not pure, so that argument doesn't hold.
Array concatenation should be considered pure because it is the
equivalent of the following function, which currently works:
pure char[] cat(string a, const(char)[] b)
{
return a ~ b;
}
void main()
{
string a;
char[] b;
char[] c = cat(a, b); // works
string s = cat(a, b); // works
}
http://dlang.org/function.html#pure-functions
We should bring the above function and the ~ operator in line with each
other. I haven't followed the discussions on GC usage in purity closely
but if 'new' is allowed, GC allocations should be allowed as well.
Ali