concept schema in category idris

This is an excerpt from Manning's book Type-Driven Development with Idris.
To into practice put the ideas you’ve learned so far, let’s now take a look at a larger example program, an interactive data store. In this section, we’ll set up the basic infrastructure. We’ll revise this program in chapter 6, as you learn more about Idris, to support key-value pairs, with schemas for describing the form of the data.
In the rest of this chapter, we’ll extend the data store by adding schemas to describe the form of the data. We’ll determine the schema by user input, and we’ll use type-level functions to compute the correct type for the data. Figure 6.4 shows two different data stores, with different schemas, that we’ll be able to represent with our extended system. Schema 1, at the top, shows a store that requires the data to be of type (Int, String), and schema 2, below, shows a store that requires the data to be of type (String, String, Int). In contrast, in the data store developed in chapter 4, the schema was effectively always String.
Figure 6.4. Two different data stores, with different schemas. Schema 1 requires the data to be of type (Int, String), and schema 2 requires the data to be of type (String, String, Int)
![]()
A typical interaction with the extended system might proceed as follows. Note that we’re describing the schema before entering any data.
The remaining hole, ?parseBySchema, is intended to convert the String the user entered into an appropriate type for the schema. You can see what’s expected by looking at its type:
rest : String schema : Schema -------------------------------------- parseBySchema : String -> SchemaType schemaAs you saw earlier, not every String will lead to a valid SchemaType schema, so you can refine this type slightly and create a top-level function that returns a Maybe (SchemaType schema) to reflect the fact that parsing the input might fail, additionally making schema explicit: