[mercury-users] type error with existentially typed data structure
Peter Ross
peter.ross at miscrit.be
Fri Sep 7 19:02:16 AEST 2001
On Thu, Sep 06, 2001 at 05:06:39PM +0200, Peter Ross wrote:
> With the attached file I get the following type error, and I am a bit
> lost as to why it occurs.
>
> petri.m:125: In clause for predicate `petri:bind_env/4':
> petri.m:125: in unification of variable `Env'
> petri.m:125: and term `BindEnv(Token)':
> petri.m:125: type error in argument(s) of higher-order term (with arity 1).
> petri.m:125: Functor (BindEnv) has type `((func T) = int)',
> petri.m:125: expected type was `((func V_9) = int)';
> petri.m:125: argument 1 (Token) has type `T',
> petri.m:125: expected type was `V_9'.
> For more information, try recompiling with `-E'.
Problem found. Don't use the automatically generated accessor functions
with existentially quantified data structures.
>
> :- pred bind_env(arc_place_transition::in, environment::out,
> petri::in, petri::out) is nondet.
>
> bind_env(ArcPlaceTransition, Env, Petri0, Petri) :-
> Place = get_place(Petri0, ArcPlaceTransition ^ from),
> BindEnv = ArcPlaceTransition ^ bind,
> set__member(Token, Place ^ tokens),
> Env = BindEnv(Token),
> Petri = Petri0.
>
If you rewrite this as
bind_env(ArcPlaceTransition, Env, Petri0, Petri) :-
ArcPlaceTransition = arc_place_transition(BindEnv, From),
Place = get_place(Petri0, ArcPlaceTransition ^ from),
set__member(Token, Place ^ tokens),
Env = BindEnv(Token),
Petri = Petri0.
You get the more usual error message of the higher order term having the
wrong inst.
Pete
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list