[mercury-users] Re: coloured petri nets
Peter Ross
peter.ross at miscrit.be
Fri Sep 7 00:15:35 AEST 2001
On Thu, Sep 06, 2001 at 02:56:49PM +0200, Peter Ross wrote:
> I think I can implement things the way I want to if I can implement the
> following functions
>
> :- type petri
> ---> ?.
> :- type ref(T)
> ---> ?.
>
> :- func get_place(petri, ref(place(T)) = place(T).
>
> In otherwords given some type petri and a reference to a place(T) in the
> type petri, get me back the place(T).
>
> Similary I will need
>
> :- pred insert_place(petri::in, place(T)::in,
> ref(place(T))::out, petri::out) is det.
>
> :- func set_place(ref(place(T)), place(T), petri) = petri.
>
Which I guess would be the following.
:- module petri2.
:- interface.
:- type petri.
:- type ref(T).
:- type place(T) ---> p(T).
:- pred insert_place(place(T)::in, ref(place(T))::out,
petri::in, petri::out) is det.
:- func get_place(petri, ref(place(T))) = place(T).
:- implementation.
:- import_module int, map, std_util.
:- type ref(T)
---> ref(int).
:- type petri
---> petri(
id :: int,
map :: map(int, univ)
).
insert_place(Place, ref(Id), petri(Id, Map0), petri(Id + 1, Map)) :-
map__det_insert(Map0, Id, univ(Place), Map).
get_place(petri(_NextId, Map), ref(Id)) = Place :-
map__lookup(Map, Id, UnivPlace),
det_univ_to_type(UnivPlace, Place).
--------------------------------------------------------------------------
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