55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
%-----------------------------------------------------------------------
|
|
|
|
sort
|
|
CardinalDirection = struct north | east | south | west;
|
|
|
|
map
|
|
otherDirection : CardinalDirection -> CardinalDirection;
|
|
|
|
eqn
|
|
otherDirection(north) = south;
|
|
otherDirection(south) = north;
|
|
otherDirection(east) = west;
|
|
otherDirection(west) = east;
|
|
|
|
%-----------------------------------------------------------------------
|
|
|
|
sort
|
|
Colour = struct red | green | yellow;
|
|
|
|
map
|
|
nextColour: Colour -> Colour;
|
|
|
|
eqn
|
|
nextColour(red) = green;
|
|
nextColour(green) = yellow;
|
|
nextColour(yellow) = red;
|
|
|
|
|
|
%------------------------------------------------------------------------
|
|
|
|
act
|
|
show : CardinalDirection # Colour;
|
|
crossingUnsafe : Colour # Colour # Colour # Colour;
|
|
safe : Bool;
|
|
emptyAct;
|
|
|
|
%------------------------------------------------------------------------
|
|
|
|
proc
|
|
TrafficLight(direction : CardinalDirection) = TF(direction, red);
|
|
|
|
TF(direction : CardinalDirection, colour : Colour) =
|
|
show(direction, colour) . TF(direction, nextColour(colour))
|
|
;
|
|
|
|
Monitor =
|
|
emptyAct
|
|
;
|
|
|
|
|
|
|
|
|
|
init
|
|
TrafficLight(north) || TrafficLight(east) || TrafficLight(south) || TrafficLight(west) || Monitor
|
|
; |