Pure functions in D
BCS
ao at pathlink.com
Mon Sep 29 15:39:24 PDT 2008
Reply to bearophile,
> Sean Kelly:
>
>> Otherwise, something like this should work:
>> void debugln_(...) { /* forward to writefln */ }
>> alias pure void function(...) SomeFn;
>> SomeFn debugln = cast(pure SomeFn) &debugln_;
> I think you have written a static cast from the function pointer of an
> impure function to a function pointer of a pure function. I kind of
> hope the compiler will forbid a cast like that, I think it may give
> troubles :-)
>
> This topic makes me more and more amused as time passes :-)
>
> Bye,
> bearophile
To forbid such a cast, you would need to forbid pointers to pure functions.
You can subvert the type system with unions if nothing else and for something
like pure, there is no point in limiting casts if there are ways around it.
union Cast (R, T...)
{
R function(T) nonPure;
pure R function(T) pure;
}
More information about the Digitalmars-d
mailing list