The State Machine

Before diving into the code, let’s visualize our simple door state machine. This will help you understand the structure we’re about to implement.

State Diagram

The state diagram below shows all possible states and the valid transitions between them:

Simple Door state diagram

In this diagram, you can see:

Transition Table

For a more structured view, here’s the corresponding transition table:

State Message State
DoorOpen Close DoorClosed
DoorClosed Open DoorOpen

Each row shows one valid transition: which state you start in, which action you take, and which state you end up in. Notice that invalid actions — like trying to open an already open door — simply don’t appear in the table.

Now let’s see how we represent this in PureScript code.

↑ Back to top