Example 1: A Simple Door

Full source code: test/Examples/Door.purs

Let’s start with a simple door state machine to demonstrate Transit’s core concepts. This example will show you how to define a state machine using Transit’s type-level DSL, implement a type-safe update function, and generate documentation automatically. We’ll compare the traditional approach with Transit’s approach to highlight the benefits of the latter.

Think of a door that can be either open or closed. When it’s open, you can close it. When it’s closed, you can open it. That’s it — no other actions make sense. You can’t open a door that’s already open, and you can’t close a door that’s already closed. This simple behavior is what we’re modeling in this example.

↑ Back to top