Library FreeSpec.Exec.Exec
This module loads a Coq plugin which provides the Exec
vernacular command. Exec is analogous to Compute, but works
with impure terms. Exec uses the Coq reduction engine to make
the head constructor of the term provided as argument for Exec
appears. Then, in presence of the request_then constructor, it
uses handler functions provided by FreeSpec users to perform the
impure tasks and compute a result. This result is passed to the
continuation, and the Exec interpreter is recursively
called. When the constructor is local, the computation is
completed.
By default, Exec uses a reduction strategy analogous to
cbn. It also accepts the nf attribute to change this
behavior, and prefers an approach analogous to
compute. Changing the reduction strategy can be handy in
presence of a term which takes a very long time to reduce with
cbn. This is typically the case with terms that relies on
well-founded recursion rather than structural recursion.
From CoqFFI Require Import Int.
From FreeSpec.Exec Require Import Eval.
From FreeSpec.FFI Require Import FFI Refs ML.
From Coq Require Import String Ascii Byte.
Extending FreeSpec.Exec
type effectful_semantic = Constr.constr list -> Constr.constr
Inductive CONSOLE : interface := | WriteLine : string -> CONSOLE unit | ReadLine : CONSOLE string.
Register <Coq Name> <Unique ID>.
Register CONSOLE freespec.exec.console.type. Register WriteLine freespec.exec.console.WriteLine. Register ReadLine freespec.exec.console.ReadLine.
let writeline = function | [str] -> print_bytes (bytes_of_coqstr str); coqtt | _ -> assert false let readline = function | [] -> string_to_coqstr (read_line ()) | _ -> assert false
val register_interface : (* The base path we have chosen to register our interface. *) string (* A list to map each constructor of this interface to an effectful semantic. *) -> (string * effectful_semantic) list -> unit
let _ = register_interface "freespec.exec.console" [("WriteLine", writeline); ("ReadLine", readline)]
Register byte as coq.byte.type.
Register REFS as freespec.ffi.REFS.type.
Register Make_ref as freespec.ffi.REFS.Make_ref.
Register Assign as freespec.ffi.REFS.Assign.
Register Deref as freespec.ffi.REFS.Deref.
Declare ML Module "freespec_exec".