[m-users.] Insts of tuple types?

Peter Wang novalazy at gmail.com
Mon Aug 7 17:38:47 AEST 2023


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 ).

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


More information about the users mailing list