Key_value.VALIDABLE
Creating a set of validators for a key-value structure only involves implementing the VALIDABLE
module.
A visitor is quite simple and can be summarised as follows:
let as_xxxx valid invalid observed_value =
if is_xxx observed_value
then valid (extract_xxx observed_value)
else invalid ()
;;
Visitor for Objects. For example, in Ezjsonm (which is a simpler wrapper for the Jsonm library), The AST is described in this way:
type value =
[ `Null
| `Bool of bool
| `Float of float
| `String of string
| `A of value list
| `O of (string * value) list
]
Implementing as_object
would be like writing this:
let as_object valid invalid = function
| `O kv -> valid kv
| _ -> invalid ()
;;