[m-users.] inst question

Volker Wysk post at volker-wysk.de
Thu Jul 28 03:12:27 AEST 2022


Hi!

I have a small program with insts, which don't work like I think they
should:

:- type either(A,B)
   ---> left(A)
   ;    right(B).

:- inst left ---> left(ground).

:- type link_parts 
   ---> link_parts(either(int, bool)).

:- inst lpleft ---> link_parts(left).


main(!IO) :-
    fsf2(link_parts(left(123)), !IO).


:- pred fsf2(link_parts::in, io::di, io::uo) is det.

fsf2(LinkParts, !IO) :-
    (
        LinkParts = link_parts(left(_)),
        fsf3(LinkParts, !IO)                    % <=== Here (line 35)
    ;
        LinkParts = link_parts(right(_))
    ).


:- pred fsf3(link_parts::in(lpleft), io::di, io::uo) is det.

fsf3(LinkParts, !IO) :-
    LinkParts = link_parts(left(Int)),
    io.format("Int=%i\n", [i(Int)], !IO).



The compiler reports an error:

test8.m:035: In clause for `fsf2(in, di, uo)':
test8.m:035:   in argument 1 of call to predicate `test8.fsf3'/3:
test8.m:035:   mode error: variable `LinkParts' has instantiatedness
test8.m:035:   `bound(link_parts(ground))',
test8.m:035:   expected instantiatedness was
test8.m:035:     named inst lpleft
test8.m:035:     which expands to
test8.m:035:       bound(
test8.m:035:         link_parts(
test8.m:035:           named inst left
test8.m:035:           which expands to
test8.m:035:             bound(
test8.m:035:               left(ground)
test8.m:035:             )
test8.m:035:         )
test8.m:035:       ).


What I don't understand, is why is the instantiatedness of LinkParts in line
35 "bound(link_parts(ground))" and not
"bound(link_parts(bound(left(ground)))" ?


Cheers,
Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mercurylang.org/archives/users/attachments/20220727/d4ef8d60/attachment.sig>


More information about the users mailing list