concept SchemaType in category idris

appears as: SchemaType, SchemaType
Type-Driven Development with Idris

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

data Schema                                                         #1
SchemaType : Schema -> Type                                         #2
data DataStore : Type where
     MkData : (schema : Schema) ->                                  #3
              (size : Nat) -> 
              (items : Vect size (SchemaType schema)) ->            #4
              DataStore 

We’ll define Schemas as being some combination of Strings and Ints, according to a definition given by the user. The user will provide a Schema, and we’ll translate the Schema to some concrete type using a type-level function, SchemaType.

The next listing shows how you can describe Schemas and convert them into Idris Types using a type-level function, SchemaType.

  rest : String
  schema : Schema
--------------------------------------
parseBySchema : String -> SchemaType schema

As 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:

parseBySchema : (schema : Schema) -> String -> Maybe (SchemaType schema)