[m-users.] Higher order type with existential quanitfication

Volker Wysk post at volker-wysk.de
Sun Oct 22 22:54:58 AEDT 2023


Hi!

I have a predicate which takes an existentially quantified type as one of
its arguments. This predicate I want to pass to another predicate. I'm
puzzled about how to declare this.


:- type hetlist
    ---> some [T] hetcons(T, hetlist)   => att(T)
    ;    hetnil.

:- pred map_hetlist(
    (some [X] pred(X, Y)),
    hetlist,
    list(Y)
).

:- mode map_hetlist(
    in(pred(in, out) is det),
    in,
    out
) is det.

map_hetlist(_, hetnil, []).

map_hetlist(Pred, hetcons(X, L), [Y|Ys]) :-
    Pred(X, Y),
    map_hetlist(Pred, L, Ys).


The compiler says:

hetlist.m:123: In declaration of predicate `map_hetlist'/3:
hetlist.m:123:   error: undefined type `[]'/0.
hetlist.m:123: In declaration of predicate `map_hetlist'/3:
hetlist.m:123:   error: undefined type `[|]'/2.
hetlist.m:123: In declaration of predicate `map_hetlist'/3:
hetlist.m:123:   error: undefined type `some'/2.


I've tried various things, and they gave me other errors.

How should I declare this?

Thanks,
Volker


More information about the users mailing list