[m-users.] inst question
Volker Wysk
post at volker-wysk.de
Thu Jul 28 19:41:33 AEST 2022
Am Mittwoch, dem 27.07.2022 um 20:34 -0700 schrieb M McDonough:
> > 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.
Actually, I want it for an input parameter. I want to make the following
ugly beginning of my predicate superfluous. All it does is to check and
accomplish the right instantiations. The "unexpected" cases are never to be
reached. All the functions in this, are field access functions:
Target = lp_link_target(LinkParts),
( lp_link_text(LinkParts) = right(_),
unexpected($pred, "Bug: Called with an embedding as the link text")
; lp_link_text(LinkParts) = left(Desc)
),
( Target = t_wikipage(TikiPage)
; Target = t_dangling_wikipage(TikiPage)
; Target = t_external(_),
unexpected($pred, "Target = " ++ string.string(Target))
; Target = t_attachment(_, _),
unexpected($pred, "Target = " ++ string.string(Target))
; Target = t_dangling_attachment(_,_),
unexpected($pred, "Target = " ++ string.string(Target))
),
The predicate makes sense only for a specific inst of a certain input
parameter. It's called from within a context which satisfies all the inst
requirements. So it would really be nice to have an inst for it, so the
"unexpected" cases don't occur and the code would be more stringent. And the
compiler checks for everyting being alright. No more "unexpected" cases.
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/20220728/c5547d45/attachment.sig>
More information about the users
mailing list