Make_validator.KV
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 ()
;;