简体   繁体   English

合金阵列模型

[英]Alloy Array Model

I just started learning alloy model language and was trying to write my own array model in Alloy. 我刚开始学习Alloy模型语言,并试图用Alloy编写自己的数组模型。 However, I was unable to extract index from a relation. 但是,我无法从关系中提取索引。 Here is my sig and fact: 这是我的信号和事实:

sig Element {}

one sig Array {
  // Map index to element
  IdxEle: Int -> Element,
  // Length of the array.
  length: Int
}

fact Index {
    all r : IdxEle | r.Int >= 0 and r.Int < length
}

The error I was getting was 我得到的错误是

This must be an integer expression.
Instead, it has the following possible type(s):
{none->none}

I looked over the reference guide but could not find a way to extract the idx field of the relation. 我查看了参考指南,但是找不到提取关系的idx字段的方法。 Can somebody help me out? 有人可以帮我吗? Thanks 谢谢

First, r in your model is of type Array->Int->Element , therefore (Array->Int->Element).Int cannot be computed since the last column in the tuple is of type Element, not Int as you seem to expect. 首先,模型中的r的类型为Array->Int->Element ,因此(Array->Int->Element).Int无法计算,因为元组中的最后一列的类型为Element,而不是Int期望。 (When you join in Alloy, the last column of the left side must be the same type of the first column of the right side.) (当您加入Alloy时,左侧的最后一列必须与右侧的第一列相同。)

Second, there are easier, more flexible, and more readable ways to express what you want: 其次,有更简单,更灵活和更具可读性的方式来表达您想要的内容:

sig Element {}

let range[start,end] = {  i : Int | i >= start and i < end }

one sig Array { index : Int -> Element } {
    index.Element = range[ 0, len[this] ]
}

fun len[ array : Array ] : Int { # array.index }

Third ... there is a built in type for you called seq . 第三...为您提供了一个内置类型seq It has everything you want and more. 它拥有您想要的一切,还有更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM