[m-users.] Question regarding predicates stored in existential data types.

Philip White philip at pswhite.org
Thu Feb 18 08:13:56 AEDT 2021


On Wed, 17 Feb 2021 14:23:00 +1100 (AEDT)
"Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:

> 2021-02-17 13:57 GMT+11:00 "Philip White" <philip at pswhite.org>:
> > Hello,
> > below is the type I have:
> > 
> > :- type flag(T)  
> >    --->    flag(                 flag_doc :: string,
> >  flag_name :: string, flag_kind :: flag_kind(T)             )
> >    ;       return_flag(T)
> >    ;       some [A] map1_flag(flag(A), pred(A::in, T::out) is det)
> >    ;       some [A, B]	map2_flag(flag(A), flag(B),
> > pred(A::in, B::in, T::out) is det).
> > 
> > When I deconstruct a value in the map2_flag case, and then try to
> > call it, I'm getting the error:
> > 
> > variable F [the variable that corresponds to the predicate part the
> > value] has instiatedness `ground', expecting higher-order pred inst
> > of arity 3.
> > 
> > Is the problem that 'ground' is not the same as pred(in, in, out) is
> > det?   
> 
> Yes, that would be the problem.
> 
> >  tried making a new inst for flag that makes everything ground,
> > except the predicate part, for which it uses a predicate
> > instantiation. However, this turned into a mess of errors, so I'm
> > not sure if I'm even on the right track.  
> 
> Unless you show us the instantiation you used, we can't be sure
> either.

Fair enough. Here's the instantiation, as well is the signature and
mode for the function that the error occurs in.

:- inst ground_flag
    --->    flag(ground, ground, ground)
    ;       return_flag(ground)
    ;       map1_flag(ground, pred(in, in, out) is det)
    ;       map2_flag(ground, ground, (pred(in, in, out) is det)).


:- pred eval_flag(flag(T), maybe(T), parsed_input,
    parsed_input, list(error_item), list(error_item)).
:- mode eval_flag(ground_flag >> ground_flag, out, in, out, in, out).

> Once this limitation is lifted, the code you wrote *should* be
> accepted by the compiler as is. Unfortunately, noone is working on
> this right now.

Okay, that makes sense. I was wondering why the compiler couldn't
figure this out, so "it could, but it doesn't" is pretty satisfactory.

- Philip


More information about the users mailing list