Define a primitive data type: Difference between revisions
Content added Content deleted
(Modula-3) |
|||
Line 417: | Line 417: | ||
} |
} |
||
} |
} |
||
=={{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>. |
|||
<lang modula3>TYPE MyInt = [1..10];</lang> |
|||
<code>MyInt</code> can now be used anywhere an <code>INTEGER</code> can, and can use 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 a runtime error. |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |