How to do a typesystem workaround ...

  • 17
  • 3

Dear specialists,

the following code snip leads to a typesystem error in the closure inside the sortBy():
type meet (datetime & void) is not a subtype of java.lang.Comparable


sequence<Order> best = new sequence<Order>(empty);
best = best.sortBy({~it => it.orderDate; }, asc);

orderDate is of type "datetime" implemented in the dates language. But datetime is a simple concept derived from Type - so indeed it does not implement the java.comparable interface.

How can i get rid of the typesystem error message. I already tried to write a new inference rule in my language for SortOperation ("sortBy") with overrides set to "true". But that does not override the original rule.

Any other possibilities ?

Best,
Dan
You can write a subtyping rule for your orderDate type to describe that Order is subtype of Comparable.

subtyping rule supertypesOf_Order {
weak = false
applicable for concept = orderDate as orderDate

rule {
return <Comparable>;
}
}

Here, <Comparable> is a quotation.

Sorry, probably, datetime should be a subtype of Comparable. It could be a bug in dates language.

Hi,

yes indeed. That works. I have created a subtype rule for the DateTimeWithTZ Concept, telling that Comparable is a subtype of datetime ...

Cool! Thanks