libretto.examples
Type members
Classlikes
Reads lines from standard input and prints them to standard output.
Reads lines from standard input and prints them to standard output.
This example implements interaction between two parties, Alice and Bob, in which
This example implements interaction between two parties, Alice and Bob, in which
- Alice sends "ping" to Bob,
- Bob sends "pong" back to Alice,
- Alice sends Done to Bob,
in this order, after which no more interaction between the two takes place.
This example demonstrates:
- A simple protocol between two parties.
- Linearity: obligation to consume every input exactly once and fulfill every demand exactly once. Linearity is key to ensuring adherence to a protocol.
- Inverting the flow of values from left-to-right to right-to-left and vice versa.
This example implements interaction between two parties, Alice and Bob, in which
This example implements interaction between two parties, Alice and Bob, in which
- when it's Alice's turn, she can choose to send "ping" to Bob or to quit;
- when it's Bob's turn, he can choose to send "pong" back to Alice, or to quit;
- interaction continues until one of the parties quits.
This is an extension of the PingPong example to multiple rounds of ping-pong. It further demonstrates:
N scientists sharing M microscopes (N > M).
N scientists sharing M microscopes (N > M).
This examples demonstrates:
- concurrency (scientists operate concurrently)
- sequencing (each scientist performs experiments sequentially, at most one at a time)
- resource sharing via pooling (the limited number of microscopes is made available throught a pool)
In a pandemic, supermarkets are required to limit the number of customers in the store. A way to do this is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customre has to wait for a previous customer to leave (and return their basket).
In a pandemic, supermarkets are required to limit the number of customers in the store. A way to do this is to provide a limited number of shopping baskets and require that each customer entering the store has a shopping basket. When there are no more baskets, an incoming customre has to wait for a previous customer to leave (and return their basket).
This example demonstrates:
- concurrency
- customers come and shop concurrently
- sequencing
- a customer can shop only after obtaining a basket
- a customer can use an item only after paying for it
- ...
- mutual exclusion
- limited number of concurrently shopping customers
- without side-effects on shared synchronization objects (such as semaphores)
- limited number of concurrently shopping customers
- linear & session types
- obligation to return a basket enforced by the type-system
- the type
Shopping
is a protocol between the store and the customer