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!
===Type constructors: union, product and composite types=== The basic types alone are of limited value. New, more structured data types are built using type constructors. {| border="1" class="wikitable" |+ style="background:#ffdead;" | Basic Type Constructors |- | <code><nowiki>T1 | T2 | ... | Tn</nowiki></code> || Union of types <code>T1,...,Tn</code> |- | <code>T1*T2*...*Tn</code> || Cartesian product of types <code>T1,...,Tn</code> |- | <code>T :: f1:T1 ... fn:Tn</code> || Composite (Record) type |} The most basic type constructor forms the union of two predefined types. The type <code>(A|B)</code> contains all elements of the type A and all of the type <code>B</code>. In the traffic signal controller example, the type modelling the colour of a traffic signal could be defined as follows: <syntaxhighlight lang="bnf"> SignalColour = <Red> | <Amber> | <FlashingAmber> | <Green> </syntaxhighlight> [[Enumerated type]]s in VDM-SL are defined as shown above as unions on quote types. Cartesian product types may also be defined in VDM-SL. The type <code>(A1*β¦*An)</code> is the type composed of all tuples of values, the first element of which is from the type <code>A1</code> and the second from the type <code>A2</code> and so on. The composite or record type is a Cartesian product with labels for the fields. The type <syntaxhighlight lang="text"> T :: f1:A1 f2:A2 ... fn:An </syntaxhighlight> is the Cartesian product with fields labelled <code>f1,β¦,fn</code>. An element of type <code>T</code> can be composed from its constituent parts by a constructor, written <code>mk_T</code>. Conversely, given an element of type <code>T</code>, the field names can be used to select the named component. For example, the type <syntaxhighlight lang="text"> Date :: day:nat1 month:nat1 year:nat inv mk_Date(d,m,y) == d<=31 and m<=12 </syntaxhighlight> models a simple date type. The value <code>mk_Date(1,4,2001)</code> corresponds to 1 April 2001. Given a date <code>d</code>, the expression <code>d.month</code> is a natural number representing the month. Restrictions on days per month and leap years could be incorporated into the invariant if desired. Combining these: <syntaxhighlight lang="text"> mk_Date(1,4,2001).month = 4 </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)