Examples

Runnable example projects for the pacta library. Each example is a self-contained Gleam project with unit / integration tests.

cd examples/<example>
gleam test
gleam run -m generate
gleam run -m generate check

Session Types (pacta/session, pacta/protocol)

ExampleDescription
atmA protocol specification, projected onto both participants, generated into typed positions, and driven from a gen_statem
bank_authBocchi-Orchard-Voinea’s asserted PIN/TAN banking protocols, weakly composed and generated into typed participants

Composed PIN/TAN banking

This example is sourced from A Theory of Composing Protocols, The Art, Science, and Engineering of Programming 7(2), article 6, 2023.

Transcription into Pacta

The contact points and control flow are the paper’s:

The adaptation is explicit. The paper writes server-local ? and ! actions. Pacta specifications are global, so these become directed Customer -> Bank and Bank -> Customer messages. Branch labels carry Nil, and the paper’s abstract payload names receive executable representations in bank_auth.

ATM

The ATM protocol from Laumann, Munksgaard and Larsen, Session Types for Rust.

The example depends on pacta by path and on eparch from Hex, because the machine and client sides drive their positions from a gen_statem and so import eparch/state_machine directly.

Search Document