Conditional Pure?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jan 22 21:03:07 PST 2011
On Saturday 22 January 2011 14:41:08 %u wrote:
> > I think this is useless. If this is possible, then you just mark every
> > single
>
> not-pure function in the program with @conditionally_pure, and we are back
> to the beginning.
>
>
> Oh, but that's not what I meant! I meant something like this:
>
> int call(TFn)(TFn fn) pure(isPure!(TFn))
> if (isCallable!(TFn))
> {
> return fn(5);
> }
>
> This way we specify purity based on a static boolean.
This has been suggested a time or two (I _definitely_ want something like this,
and I think that we _need_ it if we want pure to be truly, generally useful),
but nothing has come of it yet. Andrei's suggestion the last time this came up
was to do something similar to what you have there and make pure take a
conditional argument to determine its purity. I don't know what it will take to
get something like this in the language (I think that it's a given that it will
have to wait untill after th 64-bit port is done), but I think that it's
critical if we want purity to work with templates. And since so much of D is
likely to be templatized (in particular, Phobos uses templates quite heavily),
we _need_ purity to work with templates.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list