在阅读了 QL 中对代数数据类型的支持之后,我尝试在lgtm 控制台List
中定义一个类型:
newtype TList =
TNil()
or
TCons(int x,TList xs)
这似乎有效。但后来我尝试定义辅助类以获得toString()
谓词:
class List extends TList {
abstract string toString();
}
class Nil extends List,TNil {
override string toString() {
result = "Nil"
}
}
class Cons extends List,TCons {
override string toString() {
// what to put here?
// I would like something like result = x.toString() + ':' + xs.toString()
}
}
在这里我很难过。我不知道如何从内部x
引用构造函数参数。我试过and ,但它似乎不起作用。xs
Cons
this.x
this.xs
如何在成员谓词中引用构造函数参数?