concept request in category idris

appears as: request, request, requests
Type-Driven Development with Idris

This is an excerpt from Manning's book Type-Driven Development with Idris.

Figure 1.3. Two interacting concurrent processes, main and adder. The main process sends a request to adder, which then sends a response back to main.

In Idris, processes coordinate with each other by sending and receiving messages. Figure 1.3 shows one way this can work, with two processes, main and adder. The adder process waits for a request to add numbers from other processes. After it receives a message from main asking it to add two numbers, it sends a response back with the result.

Figure 1.3. Two interacting concurrent processes, main and adder. The main process sends a request to adder, which then sends a response back to main.

In the next listing, you can complete the definition of adder by receiving a request from the sender and then sending a reply. With unsafeRecv, you assert that the request is of type Message.

When a process receives a request of the form Add x y, it sends back a response of type Nat. You can express this relationship between the request and the response types in a type-level function:

AdderType : Message -> Type
AdderType (Add x y) = Nat

This function describes the interface that Process supports: if it receives a message of the form Add x y, it will send a response of type Nat. You could define other interfaces this way; for example, the following listing gives a description of an interface to a process that responds to requests to perform operations on lists.

  • Sent—It has sent a response to a request.