Define a primitive data type: Difference between revisions
→{{header|C sharp|C#}}
Line 191:
===Other libraries or implementation specific extensions===
As of February 2009 no open source libraries to do this task have been located.
=={{header|ATS}}==
<lang ats>(*
Here is the type:
*)
typedef rosetta_code_primitive_type =
[i : int | 1 <= i; i <= 10] int i
(*
You do not have to insert bounds checking, and the compiler inserts no
bounds checking. You simply *cannot* assign an out-of-range value.
(Proviso: unless you do some serious cheating.)
*)
implement
main0 (argc, argv) =
let
var n : rosetta_code_primitive_type
in
n := 1;
n := 10;
n := 11
end
(*
An attempt to compile this program *will fail* when it typechecks ‘n := 11’:
$ patscc primitive_type-postiats.dats
/path/to/primitive_type-postiats.dats: 282(line=11, offs=3) -- 373(line=17, offs=6): error(3): unsolved constraint: C3NSTRprop(C3TKmain(); S2Eapp(S2Ecst(<=); S2EVar(0->S2Eintinf(11)), S2Eintinf(10)))
/path/to/primitive_type-postiats.dats: 282(line=11, offs=3) -- 373(line=17, offs=6): error(3): unsolved constraint for lvar preservation
typechecking has failed: there are some unsolved constraints: please inspect the above reported error message(s) for information.
exit(ATS): uncaught exception: _2tmp_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)
*)</lang>
=={{header|C sharp|C#}}==
|