higher-order funcs for ranges (with usual interface)

spir denis.spir at gmail.com
Thu Feb 3 04:53:44 PST 2011


On 02/03/2011 01:17 PM, Lars T. Kyllingstad wrote:
> Why the reluctance to use template constraints?  They're so flexible! :)

I cannot stand the "is()" idiom/syntax ;-) Dunno why. Would happily get rid of 
it in favor of type-classes (built eg as an extension to current interfaces). 
For instance, instead of:

     void func (T) (T t)
         if (is(someConstraint1) && is(someConstraint2))
     {
         ...
     }

use:

     void func (SomeTypeClass T) (T t)
     {
         ...
     }

For instance (untested):

     void func (T) (T t)
         if (isInputRange(T) && is(ElementType!T == E))
-->
     void func (InputRange!E T) (T t)

where InputRange is a (templated) interface / type-class.

Type-class checks on /type/ /template/ parameters (as opposed to type checks on 
regular value parameters) would be performed structurally (as opposed to 
nominally). D knows how to do this, since that's what it needs to perform when 
checking is() constraints.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d-learn mailing list