On Saturday, 7 February 2015 at 09:13:19 UTC, Ziad Hatahet wrote:
On Fri, Feb 6, 2015 at 12:08 AM, Paulo Pinto via Digitalmars-d <
digitalmars-d@puremagic.com> wrote:
For example no need to check if a variable is inside a
specific range, if
the type only allows that range.
Are you referring specifically to Ada here? Otherwise, how
would ML-based
languages allow for this in a way that your traditional OO
languages would
not?
--
Ziad
Mostly Ada. An example in Ada taken from WikiBooks
(http://en.wikibooks.org/wiki/Ada_Programming/Type_System#Subtype_categories)
package Device_Driver is
type Size_Type is range 0 .. 64;
type Register is record
A, B : Boolean;
Size : Size_Type;
end record;
procedure Read (R : out Register);
procedure Write (R : in Register);
end Device_Driver;
Any attempt to assign anything outside 0..64 range to Size will
trigger an error, either at compile or run-time.
As for ML languages I was thinking that similar constraints can
be expressed via dependent types, in the variants that allow
them, but never used them.
--
Paulo