On Tue, Sep 22, 2009 at 8:48 PM, Steven Schveighoffer <schvei...@yahoo.com> wrote:
> Why have pure functions at all? Seriously, all pure function reorderings > and reuse can be rewritten by human optimization. If we aren't going to > look for places that pure functions can help optimize, why add them to the > language, it seems more trouble than its worth? > > If all it takes to optimize dynamic casts is to put pure on the function > signature, have we wasted that much time? But dynamic downcasting *isn't* pure, unless you can prove that the reference that you're downcasting is unique. class Base {} class Derived : Base {} struct S { Object o; Derived get() { return cast(Derived)o; } } void main() { S s; s.o = new Base(); writeln(s.get()); s.o = new Derived(); writeln(s.get()); } Dynamic downcasts are not pure. Simply. That's why they're *dynamic*. Without some kind of uniqueness typing, you cannot prove anything about the validity of such casts until runtime.