FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


Problem with Comparing Trees

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
Martin Meyer



Frankfurt a.M., Germany
Joined: 14 Nov 2002
Posts: 210

PostPosted: 2 Oct 2016 15:26    Post subject: Problem with Comparing Trees Reply with quote

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):

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
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3077

PostPosted: 2 Oct 2016 22:58    Post subject: Reply with quote

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:

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:

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
Prolog Development Center
Back to top
View user's profile Send private message
Martin Meyer



Frankfurt a.M., Germany
Joined: 14 Nov 2002
Posts: 210

PostPosted: 3 Oct 2016 0:15    Post subject: Reply with quote

Thank you Thomas!

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

Best regards
Martin
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum