No subject

Peter Ross peter.ross at
Wed Sep 5 22:27:05 AEST 2001


I want to write some code which mimics places in coloured petri nets.
A place in a coloured petri net has two attributes.  It contains the name
of the place and the set of tokens of some arbitary type, T, at that place.
I have modelled this by the two typeclasses below.

A petri net will consist of many different places where each place will have
a different type, T.  So I want some sort of generic container which can hold
any place, that is the existential_place type below.

Finally given an existential_place, I want to get a T out of that place,
apply some function which will map the T to an environment.  That is
the function f, below.

The code below produces the following error:

$ mmc -e place.m
place.m:027: In clause for predicate `place:f/3':
place.m:027:   unsatisfiable typeclass constraint(s):
place.m:027:   `place:place(P, U)'.
For more information, try recompiling with `-E'.

I actually suspect what I am trying to do isn't possible with Mercurys
current type system, and that I need constructor classes as well, but I
would appreciated the confirmation.


:- module place.

:- interface.

	% A place has a name.
:- typeclass place(P) where [
	func name(P) = string

	% A place contains some objects of type T.
:- typeclass place(P, T) <= place(P) where [
		% Get one of the T's stored in P.
	pred get(P::in, T::out) is nondet

:- type existential_place
	--->	some [P, T] (p(P, T) => place(P, T)).

:- type env == int.

:- implementation.

	% Given an arbitary place determine it's environment.
:- pred f(existential_place::in, (func(U) = env)::in, env::out) is nondet.

f(p(Place, _), F, Int) :-
	get(Place, T),
	Int = F(T).
mercury-users mailing list
post:  mercury-users at
administrative address: owner-mercury-users at
unsubscribe: Address: mercury-users-request at Message: unsubscribe
subscribe:   Address: mercury-users-request at Message: subscribe

More information about the users mailing list