Build a form for a record directly, in the same manner as Record_builder
or Profunctor
.
e.g.
let animal_form : (Animal.t, Animal.t, string Id.t * (bool Id.t * unit)) t =
Form.Description.Of_record.build_for_record (
Animal.Fields.make_creator
~species:(field Form.Description.string)
~can_quack:(field Form.Description.bool))
;;
Is equivalent† to:
let animal_form : (Animal.t, Animal.t, string Id.t * (bool Id.t * unit)) t =
let open Form.Description in
map (
both (contra_map ~f:Animal.species string) @@
both (contra_map ~f:Animal.can_quack bool) @@
Hlist.nil)
~f:(fun (species, (can_quack, ())) -> { Animal.species; can_quack; })
;;
† except that there is no risk of name shadowing as there would be here, but I wrote the local open only for brevity.
These are the types used for building a form by combining record fields.
Handle one field of a record using the supplied editor.
This should be used as an argument to Fields.make_creator
, see the example.
Build the form for a whole record.
This is used with an application of Fields.make_creator
as shown in the example.