After asking a question on stackoverflow and then re-reading the documentation a couple more times, I’m pretty sure that it’s currently not possible to
- insert stuff at the top of an extracted file (like library imports), or
- insert stuff at the end of an extracted file (like a call to the main function),
either on the Coq or the dune side. Duplicating the example I included over there, the code
From Coq.extraction Require Import Extraction ExtrOcamlBasic.
From Coq.Lists Require Import List.
Import ListNotations.
Parameter eqb_list : forall {a}, list a -> list a -> bool.
Extract Inlined Constant eqb_list => "(=)".
Extract Inlined Constant map => "map".
Extract Inlined Constant negb => "not".
Definition values := [true; false].
Definition xs := map negb values.
Definition ys := Eval compute in xs.
Definition sanity_test := eqb_list xs ys.
(* FIXME: prefix [open List] ; but expect this to potentially be several definitions *)
(* FIXME: suffix [;;print_endline (if sanity_test then "ok" else "not ok")] *)
Extraction "mce.ml" sanity_test.
together with the dune files (see SO question) will result in (prettified)…
let values = true :: (false :: [])
let xs = map not values
let ys = false :: (true :: [])
let sanity_test = (=) xs ys
…which doesn’t do anything and doesn’t even compile (for lack of open List
at the top.)
What I’d like to have instead is…
open List
let values = true :: (false :: [])
let xs = map not values
let ys = false :: (true :: [])
let sanity_test = (=) xs ys
;;print_endline (if sanity_test then "ok" else "not ok")
…which actually compiles and also runs a sanity check (or calls a main function for a fully functioning standalone program).
I can write a Makefile that will cat
multiple files together to add the open
statement(s, and possibly more definitions) at the top, as well as the final call to main
(and/or other sanity checks) at the end, but I’d really like to avoid falling back to Makefiles…
- Did I miss a way to do this with Coq and/or dune?
- If it’s currently not possible, is this already on the radar / coming soon? Or should I open a ticket somewhere?