[m-users.] Insts of tuple types?
Volker Wysk
post at volker-wysk.de
Mon Aug 7 22:21:09 AEST 2023
Am Montag, dem 07.08.2023 um 17:38 +1000 schrieb Peter Wang:
> On Sun, 06 Aug 2023 19:37:53 +0200 Volker Wysk <post at volker-wysk.de> wrote:
> > Hello.
> >
> > I have an argument of this type:
> >
> > maybe(
> > { (pred(io, io)),
> > place_data
> > }
> > )
> >
> > I need to specify a higher order inst because the first component is a
> > predicate. What is the inst? This inst doesn't work:
> >
> > :: out(
> > maybe(
> > { pred(di, io) is det,
> > ground
> > }
> > ))
> >
> > I get this error message:
> >
> > amend.m:099: In declaration of predicate `amend_new_file_place'/5:
> > amend.m:099: error: undefined inst `{}'/2.
>
> It's written:
>
> bound({ ArgInst1, ArgInst2 })
>
> which is the same as:
>
> bound('{}'( ArgInst1, ArgInst2 )
>
> In a inst definition you can write:
>
> :- inst tuple
> ---> { ArgInst1, ArgInst2 }.
>
> which is the same as:
>
> :- inst tuple
> ---> '{}'( ArgInst1, ArgInst2 ).
I see now. This part was missing for my inst to work:
:- inst '{}'(I, J) == bound('{}'(I, J)).
Or:
:- inst '{}'(I,J) ---> '{}'(I,J).
> BTW, in case you haven't seen the chapter on Combined higher-order types
> and insts, you can define a type with a higher-order argument type with
> insts:
>
> :- type pred_wrapper
> ---> pred_wrapper(pred(io::di, io::uo) is det).
>
> When you take the argument out of a pred_wrapper term, it will have
> the higher-order inst, so you can call it:
>
> Wrapper = pred_wrapper(P),
> P(!IO)
>
> This will save you having to specify higher-order insts everywhere.
Yes, I've done this before. It's needed because the standard libraries don't
provide for higher order insts. It's a workaround.
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/20230807/b80fb558/attachment.sig>
More information about the users
mailing list