Problem with Comparing Trees

Discussions related to Visual Prolog
Martin Meyer
VIP Member
Posts: 296
Joined: 14 Nov 2002 0:01

Problem with Comparing Trees

Unread post by Martin Meyer » 2 Oct 2016 15:26

Hello Thomas,

please have a look at this construction. It throws error c504: The expression has type 'syntaxDomains::tree{@Type}', which is incompatible with the type 'syntaxDomains::tree{::unsigned}' in (VIP 7502):

Code: Select all

interface syntaxDomains{@Type}     domains         tree = tree(subTree* SubTreeList).         subTree =             leaf(@Type Value);             branch(tree Tree). end interface syntaxDomains     implement main     open syntaxDomains{unsigned}       clauses         run() :-             Tree1 = tree([]),             Tree2 = tree([]),             _Result = toBoolean(Tree1 = Tree2).  %the error is here end implement main
But the code compiles when replacing Tree1 = Tree2 by Tree1 <> Tree2.

Regards
Martin

User avatar
Thomas Linder Puls
VIP Member
Posts: 2449
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 2 Oct 2016 22:58

We will look at it.

It is a bug, but on the other hand I will advise you to use explicit type parameters in domains instead:

Code: Select all

interface syntaxDomains   domains     tree{T} = tree(subTree{T}* SubTreeList).     subTree{T} =         leaf(T Value);         branch(tree{T} Tree).   end interface syntaxDomains   implement main     open syntaxDomains   clauses     run() :-         Tree1 = tree([]),         Tree2 = tree([]),         _Result = toBoolean(Tree1 = Tree2).   end implement main
I assume that your interface is not only parameterized because of these domains, so in a more realistic set up you can do like this:

Code: Select all

interface syntaxDomains{@Type}   domains     tree{T} = tree(subTree{T}* SubTreeList).     subTree{T} =         leaf(T Value);         branch(tree{T} Tree).   domains     treeT = tree{@Type}.     predicates     p : (treeT Tree).     q : (tree{@Type} Tree).   end interface syntaxDomains
p and q has the same type.

The main thing is that the recursive domains does not reference the type parameter of the scope (i.e. @Type), but only uses local type parameters.

The non-recursive treeT domain can reference @Type without problems.
Regards Thomas Linder Puls
PDC

Martin Meyer
VIP Member
Posts: 296
Joined: 14 Nov 2002 0:01

Unread post by Martin Meyer » 3 Oct 2016 0:15

Thank you Thomas!

I've changed my 'real' code in the way you advised, now it's working.

Best regards
Martin

Martin Meyer
VIP Member
Posts: 296
Joined: 14 Nov 2002 0:01

Re: Problem with Comparing Trees

Unread post by Martin Meyer » 18 May 2019 17:13

Hello Thomas,

I am bringing this issue back to the top because it (still or again) needs a treatment (in build 902).
Regards Martin

User avatar
Thomas Linder Puls
VIP Member
Posts: 2449
Joined: 28 Feb 2000 0:01

Re: Problem with Comparing Trees

Unread post by Thomas Linder Puls » 18 May 2019 21:57

Thank you, we will look at it.
Regards Thomas Linder Puls
PDC

Post Reply