I am trying to write a predicate that will make all Bananas and Fresh Apples expensive. I am able to achieve one of the conditions but never both. I'm very new to using Alloy, any help would be very much appreciated.
Below is my code, the error is occurring because I'm using a double In Statement but I'm unsure how I could write this without having to use two in statements. The error I receive is "Type Error, this must be a set or relation"
sig Fruit{}
sig Banana, Apple, Pear extends Fruit {}
sig Fresh, Expensive in Fruit{}
pred BananasAndFreshApplesAreExpensive {
Apple in (Expensive & Fresh) + Banana in Expensive
}
run BananasAndFreshApplesAreExpensive
If I correctly understand what you're trying to do, the code is not failing because you have 2 "in" statements, it's because you're using a union operator ("+") instead of a logical AND ("and" or "&&").
The return from a predicate has to evaluate to TRUE or FALSE.
If you are trying to say the following:
...the following code will do it:
However, if you are trying to say:
...the following code is one way to do that:
Keep in mind, though, that this does not say anything about instances of Apple that are not fresh. In other words, it will allow instances of Apple that are not fresh to be expensive.