www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Explicit Declaration of Pureness and Throwness of Higher Order Ranges

reply =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
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.
Mar 10 2014
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
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
Mar 10 2014
parent =?UTF-8?B?Ik5vcmRsw7Z3Ig==?= <per.nordlow gmail.com> writes:
 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
That's exactly the answer I asked for and wanted to hear ;) Thanks again, Sifu
Mar 10 2014