Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Vienna Development Method
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Basic types: numeric, character, token and quote types=== VDM-SL includes basic types modelling numbers and characters as follows: {| border="1" class="wikitable" |+ style="background:#ffdead;" | Basic Types |- | <code>bool</code> || [[Boolean data type|Booleans]] || {{mono|false, true}} |- | <code>nat</code> || [[natural number]]s (including zero) || {{mono|0, 1, 2, 3, 4, 5 ...}} |- | <code>nat1</code> || natural numbers (excluding zero) || {{mono|1, 2, 3, 4, 5, ...}} |- | <code>int</code> || [[integer]]s || {{mono|..., −3, −2, −1, 0, 1, 2, 3, ...}} |- | <code>rat</code> || [[rational number]]s || {{mono|a/b}}, where {{mono|a}} and {{mono|b}} are integers, {{mono|b}} is not {{mono|0}} |- | <code>real</code> || [[real number]]s || {{mono|...}} |- | <code>char</code> || characters || {{mono|A, B, C, ...}} |- | <code>token</code> || structureless tokens || {{mono|...}} |- | <code><A></code> || the quote type containing the value <code><A></code> || {{mono|...}} |} Data types are defined to represent the main data of the modelled system. Each type definition introduces a new type name and gives a representation in terms of the basic types or in terms of types already introduced. For example, a type modelling user identifiers for a log-in management system might be defined as follows: <syntaxhighlight lang="text"> types UserId = nat </syntaxhighlight> For manipulating values belonging to data types, operators are defined on the values. Thus, natural number addition, subtraction etc. are provided, as are Boolean operators such as equality and inequality. The language does not fix a maximum or minimum representable number or a precision for real numbers. Such constraints are defined where they are required in each model by means of data type invariants—Boolean expressions denoting conditions that must be respected by all elements of the defined type. For example, a requirement that user identifiers must be no greater than 9999 would be expressed as follows (where <code><=</code> is the "less than or equal to" Boolean operator on natural numbers): <syntaxhighlight lang="text"> UserId = nat inv uid == uid <= 9999 </syntaxhighlight> Since invariants can be arbitrarily complex logical expressions, and membership of a defined type is limited to only those values satisfying the invariant, type correctness in VDM-SL is not automatically decidable in all situations. The other basic types include char for characters. In some cases, the representation of a type is not relevant to the model's purpose and would only add complexity. In such cases, the members of the type may be represented as structureless tokens. Values of token types can only be compared for equality – no other operators are defined on them. Where specific named values are required, these are introduced as quote types. Each quote type consists of one named value of the same name as the type itself. Values of quote types (known as quote literals) may only be compared for equality. For example, in modelling a traffic signal controller, it may be convenient to define values to represent the colours of the traffic signal as quote types: <syntaxhighlight lang="bnf"> <Red>, <Amber>, <FlashingAmber>, <Green> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)