Re: [m-users.] Insts of tuple types?
Volker Wysk <[email protected]>
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <[email protected]> |
Am Montag, dem 07.08.2023 um 17:38 +1000 schrieb Peter Wang: > On Sun, 06 Aug 2023 19:37:53 +0200 Volker Wysk <[email protected]> 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 _______________________________________________ users mailing list [email protected] https://lists.mercurylang.org/listinfo/users
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6QXGh82Ov3+2nrxp+K4ydFOsHoUFAmTQ4bUACgkQ+K4ydFOs HoVhxhAAhprY24wnqs+/k+vevK31/H93r0mCpiiHY3dK6mV3XmBGwGEsuO7uK7F+ upM9ucR6x7llQZnIrcKuyPZMVUM+Gq8ksshkBPg+fDgTX88ZiVHd4rf9M9JaXF/P oLQRlXdwGpsZqrDj7JgDiMfmn1kE9LV5bB1rddlkLxpTwOfW4P53pWzwaZq17xaU g+zIJeAhHZGAFzLZSpxNIQh1+5PBP5BHG3kC9Sjo+ztPXDQW+H3PtMDyMYxEIDKu glAE2b0AsGYSGEcWqIhioMPF1D0oR1zjvNS4SZgty3R0xZBR2V/svaYXgS9F5ck8 LBTnK/mRgxrYVzoyk05LbXMdJoDaILV5FJ0X0UCvo4HuKqO3fqRvxgjcK7nT0D9u 3U3zTCNk4SnwIjwDNTOTc5cDaQ9T9NrPBZIbiaIC2s8E3yxKAxGZCjcN7owGgz4m QMxWgWstUDRozc5CgMtzVRoR2KsXgSAtRLUvf77/vzOUuwf8tWMYQwPldL9P/SCD 0HdumdwilQ74mDCd7Rw2lquYpRvdGzY767+eyAUxnyjYfFG7btMF70W/xHbZQoA6 mk3bmjHC5AZ+n5GSgkZCWIjOxrpXopGRodB4XkjXaQi2p9+ZAZL54imsEmeJw3K1 0n/UcN2MekykGV11NdnzpPEzW4bjLyLRR6NVDuFE8Rao8/b6ACw= =ev1M -----END PGP SIGNATURE-----