petri-netcpn-tools

How to get the elements of a UNION type?


I have the following declarations:

colset AUTHENTICATION = product INT * STRING;
colset REQUEST_PUB = product AUTHENTICATION * STRING * REAL;
colset REQUEST_SUB = product AUTHENTICATION * STRING * INT;
colset REQUEST_PUBSUB = union pub_req:REQUEST_PUB + sub_req:REQUEST_SUB;

var pubsub_req : REQUEST_PUBSUB

I have a place of type REQUEST_PUBSUB which can receive tokens of both REQUEST_PUB and REQUEST_SUB types. This place sends the variable pubsub_req to a transition. I want to operate with the pubsub_req values. For instance, testing if the string parameter of the request is some value. I am trying to do #3 pubsub_req = "some value", but I am getting the following error:

Error: operator and operand don't agree [type mismatch]
operator domain: {3:'Y;'Z}
operand: REQUEST_PUBSUB
in expression: (fn {3=3,...} => 3) pubsub_req
Elaborate failure

How to operate with the elements of a UNION type?


Solution

  • Instead of doing as I was trying, I changed the REQUEST_PUB type to:

    colset REQUEST_PUB = product AUTHENTICATION * STRING * INT;
    

    Then, I passed a list, such as ((int_var, string_var), string_var, int_var), instead of a REQUEST_PUBSUB variable. This way I could perform operations in some of the list variables.