On 26.11.2013 21:14, inout wrote:
I find this to be too verbose to be useful.

This I understand. It is actually the best argument I can find in favor of doing constraints checking upon construction, rather than in a separate construction function. This allows you to use one alias instead of two.


> And you also need to
be very careful not to discard any existing qualifiers on input
and carry them over. This will essentially make any function that
uses them to be templated, while all the instances will be the
same (yet have a different body since no D compiler merges
identical functions).

Could you give an example of this? It's a bit unclear to me what you mean. Is it this sort of thing:

  auto doPrimeStuff(Validated!(int, isPrime) a){return a;}
  auto doLessThan42Stuff(Validated!(int, lessThan42) a){return a;}

  Validated!(int, isPrime, lessThan42) i = 13;

  i.doPrimeStuff().doLessThan42Stuff();

Where the second chained function call fails due to lessThan42 being removed from the constraints? (There's also the problem that this wouldn't work in the first place due to D's lack of implicit conversions)

I still find wrapping int with some type to add a tag to it
without adding any methods is not a great idea - it doesn't scale
well with composition and tag propagation. Any operation that
expects int will essentially discard all the qualifiers.

And any operation of the kind you describe is likely to change the value so the constraints need to be checked again. abs(Validated!(int, isNegative)) cannot possibly return the same type it received.

--
  Simen

Reply via email to