Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Vienna Development Method
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Vienna Development Method
(section)
Add topic