On Sunday, 12 January 2014 at 02:11:18 UTC, Manu wrote:
But pure functions can (and do) return their arguments, and
it's obviously
not a 'strongly pure' function. So I just can't see how the
assertion that
it should be unique stands?
That's the bug. Your function isn't strongly pure, so the result
shouldn't be convertible to immutable and isn't necessarily
unique. Only strongly pure functions can have results convertible
to immutable.
Also, I was under the impression a 'strongly pure' function's
arguments
only need to be const, not necessarily immutable. Purity says
something
about the transformation performed by the function, nothing
about the data
it operates on.
Why should all arguments need to be immutable?
You don't need immutable arguments for purity, just strong
purity. It's a stronger guarantee, more than normally guaranteed.
Think of strong purity as pure + referentially transparent.
Sorry, yes you're right, they only need to be const. And it is
only if you return a mutable value that the result becomes
convertible to immutable.
int* f(const(int)* x); // convertible
const(int)* f(const(int)* x); // not-convertible
This is safe in the first instance because the result could not
have come from x due to x being const. In the second instance,
the result could have come from x, so it cannot be implicitly
converted to immutable.