Conclusion
In this example, we’ve seen how Transit helps you build type-safe state machines. We started with a simple door that can be open or closed, and learned the core workflow:
Use
Varianttypes for bothStateandMsginstead of traditional ADTs.Define the state machine using Transit’s type-level DSL specification
Implement the update function using
mkUpdatewithmatchclauses that the compiler verifies against the specificationGenerate documentation automatically — both state diagrams and transition tables — from the same specification
The key advantage is that your specification, implementation, and documentation all stay in sync because they share the same source of truth. The compiler ensures your code matches your specification, and your documentation is generated directly from it.
While this example was simple, it demonstrates Transit’s fundamental approach. In the next example, we’ll see how Transit handles more complex scenarios with states that contain data and conditional transitions.