After reading about support for algebraic datatypes in QL, I'm trying to define a List
type in the lgtm console:
newtype TList =
TNil()
or
TCons(int x,TList xs)
This seems to work. But then I try to define auxiliary classes in order to have a toString()
predicate:
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()
}
}
And here I'm stumped. I don't know how to refer to the constructor parameters x
and xs
from within Cons
. I tried this.x
and this.xs
, but it doesn't seem to work.
How can I refer to constructor parameters inside a member predicate?