[m-users.] higher order issue: `ground` seen but expecting higher-order pred

Julien Fischer jfischer at opturion.com
Wed Oct 5 14:25:22 AEDT 2022


Hi,

On Tue, 4 Oct 2022, Sean Charles (emacstheviking) wrote:

> I am fleshing out a VERY loose forth type system, I have the following definitions to allow me to set up a map of word names and there handlers:
> :- type lstr == list(string).
> 
> :- type word_handler == (pred(fstate, fstate, io, io, lstr, lstr)).
> :- inst word_handler == (pred(in, out, di, uo, in, out)is det).
> 
> :- type word_map == map(string, word_handler).
> :- type stack_entry == stack(int).

As Volker mentioned, this won't work as the inst of nearly every output
argument in the map module is ground and the higher-order inst will be
lost.

An alternative would be to use combined higher-order types and insts and
define the word_handler type as:

     :- type word_handler
         --->   word_handler(pred(fstate::in, fstate::out, io::di, io::uo, lstr::in, lstr::out) is det).

That should do what you want with fairly minimal changes elsewhere
(mainly accounting for the the word_handler wrapper that is now around
the higher-order term).

...

> I am not sure the DCG style will remain but it's pure proof of concept / exploratory at the moment.

IMO, mixing DCGs and state variables like that looks weird.

Julien.


More information about the users mailing list