[m-users.] inst question

M McDonough foolkingcrown at gmail.com
Thu Jul 28 13:34:58 AEST 2022


> 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)))" ?

You need to declare a mode which uses the inst you defined.

:- mode lpleft_in == lpleft >> lpleft.
:- pred fsf2(link_parts::lpleft_in, io.io::di, io.io::uo) is det.

The mode specifies inst transitions, for instance a func that could
only ever return lpleft would be:

:- mode lpleft_out == free >> lpleft.
:- func always_lpleft = (link_parts::lpleft_out) is det.

I think that you may find an issue (or at least annoyance) with this,
however. A pred that requires a certain input inst which works this
way can be annoying to use, as to go from an `in` link_parts in this
example you would need to write a disjunction and then destructure and
construct a new link_parts with an either of left, there isn't an
automatic way to do this without writing it out.

I think this only really makes sense for output parameters, or in the
case where you have other preds/funcs that output that specific inst,
or you will already need to switch over the data going into those
preds/funcs and so it's not extra work to switch/destructure/construct
to satisfy it.


More information about the users mailing list