Here is an example Coq program:
Module Tree.
Inductive tree (A : Type) :=
| leaf : tree A
| node : A -> tree A -> tree A -> tree A.
End Tree.
Require Extraction.
Extraction Language JSON.
Extraction "Tree.json" Tree.
Extraction Language OCaml.
Extraction "Tree.ml" Tree.
Since I am extracting the entire module, the induction principles (except the Prop ones) tree_rect and tree_rec are also extracted (they can be used for recursion, after all). This is the code I obtain from MCQC:
template<class T, class U, class V, class U = std::invoke_result_t<V, T, std::shared_ptr<tree<T>>, U, std::shared_ptr<tree<T>>, U>>
U tree_rect(U f, V f0, std::shared_ptr<tree<T>> t) {
return match(t, [=]() { return f; },
[=](auto y, auto t0, auto t1) { return f0(y, t0, tree_rect(f, f0, t0), t1, tree_rect(f, f0, t1)); });
}
This doesn't compile, since U is repeated in the template part. This problem is most apparent in induction principles but I imagine it can appear in other higher-order functions too.
In comparison, this is the code extracted to OCaml for the same induction principle:
(** val tree_rect :
'a2 -> ('a1 -> 'a1 tree -> 'a2 -> 'a1 tree -> 'a2 -> 'a2) -> 'a1 tree
-> 'a2 **)
let rec tree_rect f f0 = function
| Coq_leaf -> f
| Coq_node (y, t0, t1) -> f0 y t0 (tree_rect f f0 t0) t1 (tree_rect f f0 t1)
Here is an example Coq program:
Since I am extracting the entire module, the induction principles (except the
Propones)tree_rectandtree_recare also extracted (they can be used for recursion, after all). This is the code I obtain from MCQC:This doesn't compile, since
Uis repeated in thetemplatepart. This problem is most apparent in induction principles but I imagine it can appear in other higher-order functions too.In comparison, this is the code extracted to OCaml for the same induction principle: