Every object in an ALM system has a sort. Sorts are roughly analogous to classes in object-oriented languages or types in typed functional languages, but ALM sorts are simpler than both. Here's what you need to know:
- Sorts can optionally declare attributes. Every element of the will have instances of those attributes associated with it. These are like class-level properties, except they are immutable.
- Every sort is a subsort of another sort (except the top sort, called
universe). Any attributes associated with a sort are inherited by its subsorts.
In our fruit and basket system, fruits are obviously going to need to be an sort of object in our domain. Let's further suppose there are two kinds of fruits: apples and oranges. Here's how we would write that in ALM:
:: is called the specialization operator.
fruits :: universe reads
fruits is a subsort of
oranges are both
fruits. This means you can use an element of
an element of
fruits is required, but, obviously, you can't use an element
oranges where an element of
apples is required.
While not used in this example, the right hand side of the specialization operator accepts a comma-separated list of sorts, e.g:
You can also define a sort by explicitly enumerating its elements. Let's do that to define several varieties of apples:
Objects often have attributes associated with them, that is,
properties that are intrinsic and never change.
Let's modify our definition of
apples to include variety as an attribute:
Now, when we construct an instance of
apples, we must give an element of
varieties to be associated with it (the same would hold for any subsort
There you have it! We've defined the sorts of our fruit and basket system!
In addition to user-defined sorts, there are several built-in sorts like
naturals (the numbers 0 to ∞), and the