[mercury-users] Re: coloured petri nets

Peter Ross peter.ross at miscrit.be
Thu Sep 6 19:29:56 AEST 2001


Ok, I started with Ralphs approach, because it seemed closer in flavour
to what I wanted to do.  This is because a place will have arbitary many arcs
originating from it to various other transitions in the graph.  Each of these
arcs will bind a token to a different environment.  This seemed easier to
model with Ralphs way rather than Fergus'.


Anyway I got it to compile.

==============================================================================
:- module place2.

:- interface.

:- typeclass token(T) where [].

:- typeclass place(P) where [
		% The name of a place.
	func name(P) = string,

		% Get a token of type T from the place.
	some [T] pred get_token(P, T) => token(T),
		 mode get_token(in, out) is nondet
].

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

:- func existential_place(P) = existential_place <= place(P).

:- some [T] pred f(existential_place, ((func T) = int), int) => token(T).
:-	    mode f(in, in, out) is nondet.

:- implementation.

f(p(Place), F, Int) :-
	get_token(Place, T),
	Int = F(T).

existential_place(P) = 'new p'(P).
==============================================================================

Now I wanted to use it.

==============================================================================
:- module main.

:- interface.

:- import_module io.

:- pred main(io__state::di, io__state::uo) is det.

:- implementation.

:- import_module place2.

:- import_module int, list, set.

:- type place_int
	--->	p(set(int)).

:- instance token(int) where [].
:- instance place(place_int) where [
	name(_P) = "integer place",

	get_token(p(Set), T) :- set__member(T, Set)
].

:- func bind(int) = int.

bind(X) = 2 * X.

main -->
	{ Place = p(set__list_to_set([1,2,3])) },
	{ P = existential_place(Place) },
	(
		{ f(P, bind, X) },
		{ X = 6 }
	->
		io__write_string("Hi\n")
	;
		io__write_string("Bye\n")
	).
==============================================================================

main.m:033: In clause for predicate `main:main/2':
main.m:033:   in argument 2 of call to predicate `f/3':
main.m:033:   type error: argument has type `((func int) = int)',
main.m:033:   expected type was `((func T) = int)'.
For more information, try recompiling with `-E'.

I will now have a play with Fergus' approach.
--------------------------------------------------------------------------
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