[mercury-users] Re: coloured petri nets

Ralph Becket rbeck at microsoft.com
Thu Sep 6 20:26:12 AEST 2001


> From: Peter Ross [mailto:peter.ross at miscrit.be]
> Sent: 06 September 2001 10:30
> 
> :- 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.

The problem is that bind/1 is not polymorphic - you can't know
at compile time what type T it's going to be applied to.

Perhaps a better solution is to change things as follows:

:- typeclass token(T) where [
	func env(T) = int
].

:- typeclass place(P) where [

	func name(P) = string,

	some [T] pred token(P, T) => token(T),
               mode token(in, out) is nondet
].

%...define token/1 instances as appropriate...

:- instance token(int) where [ env(I) = I ].

main -->
	{ P = existential_place(p(list_to_set([1, 2, 3]))) },
	( if
		{ token(P, T) },
		{ env(T, X) },
		{ X = 6 }
	  then
		io__write_string("Hi\n")
	  else
		io__write_string("Bye\n")
	).

- Ralph
--------------------------------------------------------------------------
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