Define a primitive data type: Difference between revisions
Content added Content deleted
(Modula-3) |
|||
Line 419: | Line 419: | ||
=={{header|Modula-3}}== |
=={{header|Modula-3}}== |
||
In Modula-3, subrange types are automatically subtypes of their base type, so if you define a type called <code>MyInt</code> to be the subrange [1..10] then MyInt is a subtype of <code>INTEGER</code>. If we defined <code>MyChar</code> as the subrange ['A'..'C'] then MyChar would be a subtype of <code>CHAR</code>. |
In Modula-3, subrange types are automatically subtypes of their base type, so if you define a type called <code>MyInt</code> to be the subrange [1..10] then <code>MyInt</code> is a subtype of <code>INTEGER</code>. If we defined <code>MyChar</code> as the subrange ['A'..'C'] then <code>MyChar</code> would be a subtype of <code>CHAR</code>. |
||
<lang modula3>TYPE MyInt = [1..10];</lang> |
<lang modula3>TYPE MyInt = [1..10];</lang> |
||
<code>MyInt</code> can now be used anywhere an <code>INTEGER</code> can, |
<code>MyInt</code> can now be used anywhere an <code>INTEGER</code> can, such as the standard arithmetic functions. Trying to assign a value outside of the range of <code>MyInt</code> will result in a compile time warning, and/or a runtime error. |
||
=={{header|OCaml}}== |
=={{header|OCaml}}== |