Explicit Declaration of Pureness and Throwness of Higher Order Ranges

Jonathan M Davis jmdavisProg at gmx.com
Mon Mar 10 15:34:20 PDT 2014


On Monday, March 10, 2014 22:02:39 Nordlöw wrote:
> Is it, in D today, possible to explicitly tag higher order ranges
> such as for example `map` with their pureness, safeness and
> throwness based on the corresponding properties on their function
> arguments such as `fun...`?
> 
> And is this motivated? now that the D compiler deduce these
> properties for us automagically?
> 
> I guess if we had some intricate IDE-integration with DMD/DCD or
> alike these properties could be automatically presented to the
> programmer for each range instantiation.

I'm not quite sure what you're asking. You either mark a function as @safe, 
pure, and/or nothrow - or you don't, in which case, if it's a templated 
function, the attributes are inferred to the best of the compiler's 
capabilities, and if it's not, then the function doesn't have those 
attributes.

If you're asking whether we should prefer to be explicit with attributes on 
template functions, then the answer is no. We want the inference to be done by 
the compiler for the very reason that it was introduced in the first place. 
Without inference, if the function is marked with @safe, pure, or nothrow, 
then that restricts the list of valid template arguments to arguments that 
fulfill those requirements, and if we don't mark the templated function as 
@safe, pure, or nothrow, then it can't be used in other functions marked with 
those attributes.

Now, prior to dmd 2.065, the attribute inference was pretty poor, but it looks 
like the various bugs with regards to that were fixed: 

http://dlang.org/changelog.html#attribinference2

So, attribute inference should be working much better now.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list