Search code examples
alloy

How to map constraint-centric Alloy models to programming language code?


I really like designing Alloy models by simply listing the constraints and then running the Alloy Analyzer: Find the instances that satisfy the constraints.

But it occurred to me that mapping such constraint-centric Alloy models into programming language code might be difficult. There probably isn’t going to be a one-to-one mapping of Alloy constraint expressions to, say, Java statements. Indeed, mapping a list of Alloy constraint expressions to Java code is likely be quite difficult.

If there is a huge semantic/syntactic gap between the Alloy expressions and the programming language code, then isn’t the benefit of Alloy diminished?

Would it be better to not design constraint-centric Alloy models? Would it be better to instead design algorithmic-centric Alloy models (i.e., make Alloy models that look like programming language code), to decrease the semantic/syntactic gap?

I am eager to hear your thoughts on this.


Solution

  • Two comments from me:

    1. It ist possible to program in a constraint-based way. See logic programming languages.

    2. But even if you use a conventional programming language: implicitly, the model is always there. It is just not expressed in the program code.

    So, in my opinion, this gap does not diminish the benefit of Alloy, and it would be wise to make your models as declarative as possible.