How to define complex type relations in TS
In my language, types consist of two parts, say
class
androle
. I can define the individual subclass and subrole relations, say<class:
and<role:
by storing instances usingwhere store
.Now, I would like to define the combined subtype relation between two types
Asked by Michael on 12 August 2015 at 11:20(class1, role1) <: (class2, role2)
, which requiresclass1 <class: class2
androle1 <role: role2
. How can I do that?
3 Answers
I think this should work:
Answered by Jeff Smits on 12 August 2015 at 18:50(class1,role1) <: (class2,role2) where class1 <class: class2 and role1 <role: role2
Thank you for your answer. I found more information about custom relation definitions on the TS bug tracker. Is this really the only “documentation” about this feature?..
Then, unfortunately, it doesn’t work. I got it running like this:
Assign(l, r) :- where ( l : tl and tl => RoleType(rl, cl) and r : tr and tr => RoleType(rr, cr) and rr <role: rl and cr <class: cl ) else error $[right-hand side type [tr] is not a subtype of [tl]] on r
but when I change it to this:
RoleType(r1, c1) <: RoleType(r2, c2) where r1 <role: r2 and c1 <class: c2 Assign(l, r) :- where ( l : tl and r : tr and tr <: tl ) else error $[right-hand side type [tr] is not a subtype of [tl]] on r
then I get subtyping errors everywhere.
Any ideas?
Answered by Michael on 13 August 2015 at 11:27
No idea. All I know is custom relations like this don’t always work, and I suspect that’s why they aren’t documented. It’s probably just work in progress.
Answered by Jeff Smits on 13 August 2015 at 17:14