From - Thu Jun 20 10:13:39 1996 Received: (from daemon@localhost) by daimi.daimi.aau.dk (8.6.13/8.6.13) id KAA28046; Thu, 20 Jun 1996 10:12:02 +0200 Date: Thu, 20 Jun 1996 10:12:02 +0200 Message-Id: <199606200812.KAA28046@daimi.daimi.aau.dk> To: designCPN-owner@daimi.aau.dk From: designCPN-owner@daimi.aau.dk Subject: BOUNCE designcpn@daimi.aau.dk: Approval required Status: RO >From desgncpn@daimi.aau.dk Thu Jun 20 10:11:55 1996 Received: from [130.225.16.125] (luna.daimi.aau.dk [130.225.16.125]) by daimi.daimi.aau.dk (8.6.13/8.6.13) with SMTP id KAA28040 for ; Thu, 20 Jun 1996 10:11:53 +0200 X-Sender: sorenchr@130.225.16.1 Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Thu, 20 Jun 1996 10:11:55 +0200 To: designCPN@daimi.aau.dk From: schristensen@daimi.aau.dk (Soren Christensen) Subject: Re: Arbitrary ML datatypes as colour sets? >Since this may be the first user message in this forum, let me >start by expressing my thanks to the CPN group at Aarhus. Thank >you for taking over (distribution, development and support of) >Design/CPN. This means a lot of (non-research) work for you, but >it should also provide an environment in which information and >experiences are shared more freely. I hope it will help the >formalism and tool to spread and flourish. Thanks, hope we will all benefit from the arrangement. >Now, here is my problem. > >CPN ML is usually described as an extension of Standard ML. >To quote from : > > Design/CPN use CPN ML which is obtained by extending > Standard ML in three different ways. > > The first extension adds syntactic sugar for colour set > declarations. This makes it very easy to declare the most > common kinds of colour sets. It also means that the user > can include a number of predefined functions, just by > mentioning their name in a colour set declaration. > >But what if I need to use other Standard ML datatypes >as colour sets, e.g., recursive datatypes or function types? > >Is it possible to bypass the syntactic sugar for colour set >declarations and how can I do it? Yes, it is possible! There are some restrictions: 1) The built-in test for equality, = , must work for the type! For ML this means that you cannot use function types and abstract data types. And for all other datatypes the values must be structurally equal to satisfy the = test (this is the reason we have defined the == operator to test non- structural equality of multi sets). 2) You must specify 3 functions for the type: ran : mapping unit into a value of the type lt : providing an ordering of values of the type mkst_col : create a string representation of a value of the type. ran is used in interactive simulations when you have to bind free variables of a type with many elements. If you do not use free variables of the type, or do not use interactive simulations you can just define a dummy ran function - as long as it matches the type requirements. lt is used to order elements of multi sets - e.g. before showing the current marking of a place. mkst_col is used to map a value to a string. This is necessary for showing the current marking in the simulator. It is also used inside the "Bind" or "Change Marking" dialog, and this means that it is important that the string representation of a value will evaluate to the same value when it is given to the ML system. Below you will find a small example of how declarations in the global declaration node can look. If you have a real example I would like to have a copy to include in our WWW examples. Global declaration node: ------ color I = int; color elm = record value1 : I * value2 : I declare ran, lt, mkst_col; datatype T = Branch of T * T | Leaf of elm | Cut_off; color one_to_three = int with 1..3 declare ran; fun my_random () = case (ran'one_to_three ()) of 1 => Branch (my_random (), my_random ()) | 2 => Leaf (ran'elm ()) | _ => Cut_off; fun my_lt (Branch (t1,t2), Branch (t3,t4)) = if my_lt (t1,t3) then true else ((t1 = t3) andalso (my_lt (t2,t4))) | my_lt (Branch _, _) = false | my_lt (_, Branch _) = true | my_lt (Leaf e1, Leaf e2) = lt'elm (e1,e2) | my_lt (Leaf _, _) = false | my_lt (_, Leaf _) = true | my_lt (Cut_off, Cut_off) = false; fun my_mkst_col (Branch (t1,t2)) = "Branch ("^(my_mkst_col t1)^", "^(my_mkst_col t2)^")" | my_mkst_col (Leaf e1) = "Leaf ("^(mkst_col'elm e1)^")" | my_mkst_col Cut_off = "Cut_off"; color Tree = T with (my_lt, my_random, my_mkst_col); var x,y,z : Tree; ------- The color Tree can be used as any other color declared in the usual way. For this color construction you can declare ran, lt, mkst_col and mkst_ms. To yield the functions ran'Tree, lt'Tree, mkst_col'Tree and mkst_ms'Tree. Hope this explanation helps. Best regards Soren --------------------------------------------------------------------- | Soren Christensen, Computer Science Department, Aarhus University | | Ny Munkegade 116, DK-8000 Aarhus C, DENMARK | | email: schristensen@daimi.aau.dk | phone: +45 89 42 32 65 | | telefax: +45 89 42 32 55 | phone at home: +45 86 93 63 26 | | WWW URL: | --------------------------------------------------------------------- --- [[ Post messages and summary of replies: designCPN@daimi.aau.dk ]] [[ To (un)subscribe, send "help" to: Majordomo@daimi.aau.dk ]] [[ The moderator's address: designCPN-owner@daimi.aau.dk ]] [[ World Wide Web URL: http://www.daimi.aau.dk/designCPN/email/ ]]