On Wednesday, 25 June 2014 at 20:59:00 UTC, Justin Whear wrote:
On Wed, 25 Jun 2014 15:33:14 +0000, bearophile wrote:
I think where you expect a String you can send a
Social_Security_Number,
but where it expects a Social_Security_Number it doesn't
accept a
String. (The Dynamic_Predicate and Static_Predicate of modern
Ada allow
to perform such restrictions.) So I think there are some
analogies with
OOP.
I'd like to do something like this in D, with structs/values.
Bye,
bearophile
Does this do everything you're looking for?
http://dpaste.dzfl.pl/50531f5b1356
The only potential problem I see is that the invariant
presumably won't
be compiled in when in release mode.
Now if only we could get that to work with more than one type,
such that we could have subtype implicitly convertible to more
than one type.