Hi there,
I have the following small example: I want to send a query to elpi & then inspect the structure of the solution to
construct a term in OCaml (i.e., decode from an elpi term to some ocaml type).
open Elpi.API
let global = Ast.Loc.initial "init"
let base_str =
{| kind foo type.
type mk_t int -> foo.
type is_t foo -> int -> (pred).
is_t (mk_t N) N.
|}
let is_t_c = RawData.Constants.declare_global_symbol "is_t"
let mk_t_c = RawData.Constants.declare_global_symbol "mk_t"
let query =
Ast.Term.mkAppGlobal ~loc:global ~hdloc:global is_t_c
(Ast.Term.mkVar ~loc:global ~hdloc:global (Ast.Name.from_string "X") [])
[Ast.Term.mkOpaque ~loc:global (RawOpaqueData.int.cino 4)]
let () = begin
let flags = { Compile.default_flags with Compile.print_units = true } in
let elpi = Setup.init
~builtins:[Elpi.Builtin.std_builtins]
~flags:(Compile.to_setup_flags flags)
~file_resolver:(Parse.std_resolver ~paths:[] ()) () in
let base = Parse.program_from ~elpi ~loc:global ~digest:(Digest.string "") (Lexing.from_string base_str) in
let pgm = Compile.program ~flags ~elpi base in
let query = Compile.optimize @@ RawQuery.compile_term pgm (fun st -> st, query) in
match Execute.once query with
| Execute.Success r ->
Setup.StrMap.iter begin fun k v ->
match RawData.look ~depth:0 v with
| RawData.App (c, _, _) ->
Format.printf "Solution: %a, %d, %d\n"
(Pp.term r.pp_ctx) v
c
mk_t_c
| _ -> exit 1
end r.assignments
| _ -> exit 1
end
You can see that I declare a constant mk_t_c corresponding to mk_t. However, when I run the program, I get output like:
Solution: mk_t 4, -418, -73
so it is clear I can not simply compare the view's App's constant against the one that I declare in my program.
I am assuming that that this approach must not be the right way to go about decoding the solution term, but I'm at a loss for the right way to do it. In the general case, I do expect there to be unsolved unification variables - does that matter? Is there an example I can reference? The tini-ml example that is checked in seems stale & also stops short of the decode step.
Thank you!
Hi there,
I have the following small example: I want to send a query to elpi & then inspect the structure of the solution to
construct a term in OCaml (i.e., decode from an elpi term to some ocaml type).
You can see that I declare a constant
mk_t_ccorresponding tomk_t. However, when I run the program, I get output like:so it is clear I can not simply compare the
view'sApp's constant against the one that I declare in my program.I am assuming that that this approach must not be the right way to go about decoding the solution term, but I'm at a loss for the right way to do it. In the general case, I do expect there to be unsolved unification variables - does that matter? Is there an example I can reference? The tini-ml example that is checked in seems stale & also stops short of the decode step.
Thank you!