Re: [m-users.] Insts of tuple types?

Peter Wang <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
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 ).

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.

Peter
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.