Patterns may be composed in VTCL a complex way by using the find construct. Moreover, the injectivity of pattern matching can be further controlled by using the new shareable keyword as follows:
The following examples highlight the semantic corner cases using of pattern composition and injective pattern matching. As a example, we use a simple state machine formalism (with states as entities and transitions as relations), which potentially contain loop transitions (where the source and target state of a transition is the same).
// A and B should be different, i.e. loop transitions are not matched pattern childPatternInj1(A, B) = { state(A); state.transition(T, A, B); state(B); }
// A and B may be equal, loop transitions are matched shareable pattern childPatternSha1(A, B) = { state(A); state.transition(T, A, B); state(B); }
// Equivalent match set with childPatternInj1: A =/= B pattern childPatternInj2(A, B) = { find childPatternSha1(A, B); }
// Equivalent match set with childPatternInj1: A =/= B shareable pattern childPatternSha2(A, B) = { find childPatternSha1(A, B); A =/= B; }
And now, let us present some more complex scenarios. As a general rule, the caller (parent) pattern may prescribe additional injectivity constraints for the local variables.
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern) pattern parentPattern1(X, Y, Z) = { find childPatternInj1(X, Y); find childPatternInj1(Y, Z); }
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern) pattern parentPattern2(X, Y, Z) = { find childPatternInj1(X, Y); find childPatternSha1(Y, Z); }
// Constraints: X =/= Y, Y =/Z, X =/= Z (thanks to the injectivity of the parent pattern) pattern parentPattern3(X, Y, Z) = { find childPatternSha1(X, Y); find childPatternSha1(Y, Z); }
// Constraints: X =/= Y, Y =/Z (thanks to the injectivity of the child pattern) shareable pattern parentPattern4(X, Y, Z) = { find childPatternInj1(X, Y); find childPatternInj1(Y, Z); }
// Constraints: X =/= Y (thanks to the injectivity of the child pattern) shareable pattern parentPattern5(X, Y, Z) = { find childPatternInj1(X, Y); find childPatternSha1(Y, Z); }
// Constraints: none shareable pattern parentPattern6(X, Y, Z) = { find childPatternSha1(X, Y); find childPatternSha1(Y, Z); }