Bug on unconstrained Strings

≯℡__Kan透↙ 提交于 2021-02-11 18:06:08

问题


Alloy appears to have a bug when relations include unconstrained Strings. No instance is found for the following:

sig foo{
    bar: String,
    yak: Int
}
pred show[]{one f:foo | f.yak=0}
run show for 1

If we change this to bar: Int, Alloy finds an instance with an arbitrary value.


回答1:


This "known for ages" bug has thankfully a workaround. For things to work, you need to "implicitly declare" some string values by using them in a fact or a predicate.

As an example, the following signature fact will allow bar to take its value in {"a","b","c"} :

sig foo{
   bar: String,
   yak: Int
}{
   bar in "a"+"b"+"c"
}

You can also define a pool of string to be used instance wide as follows:

fact stringPool{
   none!= "a"+"b"+"c"+"d"+"e"
}

See:

Provide Alloy with a "pool" of custom Strings

Problem in generation of world in predicate

How to use String in Alloy?

and so on ...




回答2:


Thanks for the bug report. Can you file an issue?

BTW, strings are not well supported in Alloy. In general it's best to avoid any concrete types unless you really need them, and do everything with abstract ones. Most uses of integers aren't necessary either.



来源:https://stackoverflow.com/questions/57503426/bug-on-unconstrained-strings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!