In addition to the previous accepted answer, I'd like to add some useful insights coming from a one-week experience with Alloy on enum
s, in particular on the main differences with standard sig
.
If you use abstract sig + extend
, you'll come up with a model in which there are many sets corresponding to the same concept. Maybe an example could clarify it better.
Suppose somthing like
sig Car {
dameges: set Damage
}
You have the choice to use
abstract sig Damage {}
sig MajorDamage, MinorDamage extends Damage {}
vs
enum Damage {
MajorDamage, MinorDamage
}
In the first case we can come up wiht a model with different MinorDamage atoms (MinorDamage0, MinorDamage1, ...) associatet to Cars, while in the second case you always have only one MinorDamage to which different Cars can refer.
It could have some sense in this case to use an abstract sig + extend
form (because you can decide to track different MinorDamage or MajorDamage elements).
On the other hand, if you want to have a currentState: set State
, it could be better to use an
enum State {Damaged, Parked, Driven}
to map the concept, in order to have exactly three State
to which each Car
can refer to. In this way, in the Visualizer
, you can decide to project your model on exactly one of the states and it will highlight all the Car
s associated to this state. You can't do that with the abstract + extend
construct, of course, because projecting over MajorDamage0
will highlight only the Car
associated to that Damage
and nothing else.
So, in conclusion, it really depends on what you have to do.
Also, keep in mind that if you have an enum composed by X elements and execute
run some_predicate for Y
where Y < X, Alloy produces no instance at all.
So, in our last example, we can't have a Y < 3.
As a last note, enums don't always appear in the Visualizer if you use the Magic Layout button, but as I said previously you can "project" your model over the enum and switch between the different elements of the enum.