├── .gitattributes ├── .github └── workflows │ ├── doc.yml │ ├── main.yml │ └── users.yml ├── .gitignore ├── .ocamlformat ├── AUTHORS.md ├── CHANGES.md ├── ELPI.md ├── INCOMPATIBILITIES.md ├── LICENSE ├── Makefile ├── README.md ├── docs ├── Makefile ├── base │ ├── a.elpi │ ├── about.rst │ ├── conf.py │ ├── index.rst │ └── playground.rst └── engine │ └── engine.py ├── dune ├── dune-project ├── elpi.opam ├── elpi_REPL.ml ├── src ├── API.ml ├── API.mli ├── builtin.elpi ├── builtin.ml ├── builtin.mli ├── builtin_map.elpi ├── builtin_set.elpi ├── builtin_stdlib.elpi ├── compiler │ ├── compiler.ml │ ├── compiler.mli │ ├── compiler_data.ml │ ├── determinacy_checker.ml │ ├── determinacy_checker.mli │ ├── dune │ ├── spilling.ml │ ├── spilling.mli │ ├── test_compiler_data.ml │ ├── test_type_checker.ml │ ├── test_union_find.ml │ ├── type_checker.ml │ └── type_checker.mli ├── dune ├── dune.config ├── elpi_trace_elaborator.ml ├── parser │ ├── README.md │ ├── ast.ml │ ├── ast.mli │ ├── dune │ ├── error_messages.txt │ ├── gen_infix_lexer.ml │ ├── gen_token_precedence.ml │ ├── grammar.mly │ ├── lexer.mll.in │ ├── lexer_config.ml │ ├── parse.ml │ ├── parse.mli │ ├── parser_config.ml │ ├── test_lexer.ml │ ├── test_parser.ml │ ├── token_precedence.mly │ └── tokens.mly ├── runtime │ ├── bl.ml │ ├── bl.mli │ ├── data.ml │ ├── discrimination_tree.ml │ ├── discrimination_tree.mli │ ├── dune │ ├── ptmap.ml │ ├── ptmap.mli │ ├── runtime.ml │ ├── runtime.mli │ ├── runtime_trace_off.ml │ ├── runtime_trace_off.mli │ ├── test_bl.ml │ ├── test_discrimination_tree.ml │ └── test_lex.ml ├── trace.atd ├── trace_atd.ts └── utils │ ├── dune │ ├── union_find.ml │ ├── union_find.mli │ ├── util.ml │ └── util.mli ├── tests ├── dune ├── dune-project ├── plot ├── sources │ ├── GH_issue_19.elpi │ ├── accumulate_twice1.elpi │ ├── accumulate_twice2.elpi │ ├── accumulated.elpi │ ├── ackermann.elpi │ ├── asclause.elpi │ ├── bad_index.elpi │ ├── beta.elpi │ ├── block.elpi │ ├── broken_trace1.elab.json │ ├── broken_trace1.json │ ├── broken_trace2.json │ ├── bug-256.elpi │ ├── bug_226.elpi │ ├── chr-scope-change-failure.elpi │ ├── chr-scope-change.elpi │ ├── chr-scope.elpi │ ├── chr.elpi │ ├── chrGCD.elpi │ ├── chrLEQ.elpi │ ├── chr_nokey.elpi │ ├── chr_nokey2.elpi │ ├── chr_not_clique.elpi │ ├── chr_sem.elpi │ ├── chr_with_hypotheses.elpi │ ├── conj2.elpi │ ├── crypt.mod │ ├── crypt.sig │ ├── ctx_loading.elpi │ ├── cut.elpi │ ├── cut2.elpi │ ├── cut3.elpi │ ├── cut4.elpi │ ├── cut5.elpi │ ├── cut6.elpi │ ├── deep_indexing.elpi │ ├── discard.elpi │ ├── dt.elpi │ ├── dt1.elpi │ ├── dt_bench.elpi │ ├── dt_bug272.elpi │ ├── dt_bug323.elpi │ ├── dt_empty_list.elpi │ ├── dt_empty_list.log │ ├── dt_inst_compiler.elpi │ ├── dt_max_depths.elpi │ ├── dt_max_depths.log │ ├── dt_multiparam1.elpi │ ├── dt_multiparam2.elpi │ ├── dt_multiparam3.elpi │ ├── dt_multivar.elpi │ ├── dt_multivar_long_list.elpi │ ├── dt_off.elpi │ ├── dt_order.elpi │ ├── dt_var.elpi │ ├── dt_var2.elpi │ ├── dt_var3.elpi │ ├── dune │ ├── elpi_only_llam.elpi │ ├── end_comment.elpi │ ├── eta.elpi │ ├── eta_as.elpi │ ├── eta_oc.elpi │ ├── even-odd.elpi │ ├── fast_mu.mod │ ├── fast_mu.sig │ ├── findall.elpi │ ├── findall_csts.elpi │ ├── fragment_exit.elpi │ ├── fragment_exit2.elpi │ ├── fragment_exit3.elpi │ ├── functionality │ │ ├── .gitignore │ │ ├── README.md │ │ ├── heads │ │ │ ├── heads01.elpi │ │ │ ├── heads02.elpi │ │ │ ├── heads03.elpi │ │ │ ├── heads04.elpi │ │ │ ├── heads05.elpi │ │ │ ├── heads06.elpi │ │ │ ├── heads07.elpi │ │ │ ├── heads08.elpi │ │ │ └── heads09_TODO.elpi │ │ ├── meals.elpi │ │ ├── test1.elpi │ │ ├── test1.m │ │ ├── test10.elpi │ │ ├── test100.elpi │ │ ├── test101.elpi │ │ ├── test102.elpi │ │ ├── test103.elpi │ │ ├── test104.elpi │ │ ├── test105.elpi │ │ ├── test106.elpi │ │ ├── test107.elpi │ │ ├── test108.elpi │ │ ├── test109.elpi │ │ ├── test11.elpi │ │ ├── test110.elpi │ │ ├── test111.elpi │ │ ├── test112.elpi │ │ ├── test113.elpi │ │ ├── test114.elpi │ │ ├── test115.elpi │ │ ├── test116.elpi │ │ ├── test117.elpi │ │ ├── test118.elpi │ │ ├── test12.elpi │ │ ├── test13.elpi │ │ ├── test14.elpi │ │ ├── test15.elpi │ │ ├── test16.elpi │ │ ├── test16.m │ │ ├── test17.elpi │ │ ├── test18.elpi │ │ ├── test18.m │ │ ├── test19.elpi │ │ ├── test2.elpi │ │ ├── test2.m │ │ ├── test20.elpi │ │ ├── test21.elpi │ │ ├── test22.elpi │ │ ├── test22.m │ │ ├── test23.elpi │ │ ├── test24.elpi │ │ ├── test24.m │ │ ├── test25.elpi │ │ ├── test26.elpi │ │ ├── test27.elpi │ │ ├── test28.elpi │ │ ├── test29.elpi │ │ ├── test29.m │ │ ├── test3.elpi │ │ ├── test30.elpi │ │ ├── test30.m │ │ ├── test31.elpi │ │ ├── test32.elpi │ │ ├── test33.elpi │ │ ├── test34.elpi │ │ ├── test35.elpi │ │ ├── test36.elpi │ │ ├── test37.elpi │ │ ├── test38.elpi │ │ ├── test39.elpi │ │ ├── test3_1.elpi │ │ ├── test4.elpi │ │ ├── test40.elpi │ │ ├── test41.elpi │ │ ├── test42.elpi │ │ ├── test43.elpi │ │ ├── test44.elpi │ │ ├── test45.elpi │ │ ├── test46.elpi │ │ ├── test47.elpi │ │ ├── test48.elpi │ │ ├── test49.elpi │ │ ├── test5.elpi │ │ ├── test5.m │ │ ├── test50.elpi │ │ ├── test51.elpi │ │ ├── test52.elpi │ │ ├── test52.m │ │ ├── test53.elpi │ │ ├── test54.elpi │ │ ├── test55.elpi │ │ ├── test56.elpi │ │ ├── test57.elpi │ │ ├── test58.elpi │ │ ├── test59.elpi │ │ ├── test6.elpi │ │ ├── test60.elpi │ │ ├── test61.elpi │ │ ├── test62.elpi │ │ ├── test63.elpi │ │ ├── test64.elpi │ │ ├── test65.elpi │ │ ├── test66.elpi │ │ ├── test67.elpi │ │ ├── test68.elpi │ │ ├── test69.elpi │ │ ├── test7.elpi │ │ ├── test70.elpi │ │ ├── test71.elpi │ │ ├── test72.elpi │ │ ├── test73.elpi │ │ ├── test74.elpi │ │ ├── test75.elpi │ │ ├── test76.elpi │ │ ├── test77.elpi │ │ ├── test78.elpi │ │ ├── test79.elpi │ │ ├── test8.elpi │ │ ├── test80.elpi │ │ ├── test81.elpi │ │ ├── test82.elpi │ │ ├── test83.elpi │ │ ├── test84.elpi │ │ ├── test85.elpi │ │ ├── test86.elpi │ │ ├── test87.elpi │ │ ├── test88.elpi │ │ ├── test89.elpi │ │ ├── test9.elpi │ │ ├── test90.elpi │ │ ├── test91.elpi │ │ ├── test92.elpi │ │ ├── test93.elpi │ │ ├── test94.elpi │ │ ├── test95.elpi │ │ ├── test96.elpi │ │ ├── test97.elpi │ │ ├── test98.elpi │ │ ├── test99.elpi │ │ └── various.m │ ├── general_case.elpi │ ├── general_case2.elpi │ ├── general_case3.elpi │ ├── graft_before.elpi │ ├── graft_before_same.elpi │ ├── graft_remove.elpi │ ├── graft_replace_err.elpi │ ├── graft_replace_ok.elpi │ ├── hc_interp.elpi │ ├── hdclause.elpi │ ├── heap_discard.elpi │ ├── helena_elpi │ │ ├── Makefile │ │ ├── grundlagen.txt │ │ ├── grundlagen_2b_ld3.elpi │ │ ├── grundlagen_types.elpi │ │ ├── helena.elpi │ │ ├── lambdadelta.elpi │ │ ├── ld3_engine.elpi │ │ └── test_31_2nd.txt │ ├── hilbert │ │ ├── README │ │ ├── hilbert.mod │ │ └── hilbert.sig │ ├── hilbert2 │ │ ├── README │ │ ├── hilbert2.mod │ │ └── hilbert2.sig │ ├── ho.elpi │ ├── hollight.elpi │ ├── holp │ │ ├── README │ │ ├── hc_interp.mod │ │ ├── hc_interp.sig │ │ ├── hc_syntax.mod │ │ ├── hc_syntax.sig │ │ ├── hcinterp_examples.mod │ │ ├── hcinterp_examples.sig │ │ ├── hcsyntax_examples.mod │ │ ├── hcsyntax_examples.sig │ │ ├── lists.mod │ │ ├── lists.sig │ │ ├── logic_basic.sig │ │ ├── logic_types.sig │ │ ├── logic_vocab.sig │ │ ├── main.mod │ │ ├── main.sig │ │ ├── pnf.mod │ │ ├── pnf.sig │ │ ├── pnf_examples.mod │ │ ├── pnf_examples.sig │ │ ├── refl_syntax.mod │ │ └── refl_syntax.sig │ ├── hyp_uvar.elpi │ ├── ifdef.elpi │ ├── impl.elpi │ ├── impl2.elpi │ ├── impl_prec.elpi │ ├── impl_prec_ok.elpi │ ├── index2.elpi │ ├── io_colon.elpi │ ├── is.elpi │ ├── lambda.elpi │ ├── lambda2.elpi │ ├── lambda3.elpi │ ├── lambda3.mod │ ├── lambda3.sig │ ├── lambda4.elpi │ ├── lambda5.elpi │ ├── lambda6.elpi │ ├── ld-3C │ │ ├── Makefile │ │ ├── grundlagen_2b_ld3.elpi │ │ ├── grundlagen_pars.elpi │ │ ├── grundlagen_types.elpi │ │ ├── ld3c_engine.elpi │ │ ├── ld3c_global.elpi │ │ ├── ld3c_kernel.elpi │ │ ├── ld3c_kernel_0.elpi │ │ ├── ld3c_kernel_1.elpi │ │ ├── ld3c_trace.elpi │ │ ├── ld3c_types.elpi │ │ └── reductions.tex │ ├── linear.elpi │ ├── list_as_conj.elpi │ ├── list_comma.elpi │ ├── llam.elpi │ ├── llam.mod │ ├── llam.sig │ ├── llamchr.elpi │ ├── lyp │ │ ├── Makefile │ │ ├── grundlagen_2b_lyp.elpi │ │ ├── lyp_engine.elpi │ │ ├── lyp_global.elpi │ │ ├── lyp_machine.elpi │ │ ├── lyp_trace.elpi │ │ ├── reductions.txt │ │ ├── test_31_1.txt │ │ ├── test_31_2.txt │ │ └── test_31_3.txt │ ├── macro_type.elpi │ ├── macro_type_err_pos.elpi │ ├── map.elpi │ ├── map_ho.elpi │ ├── map_list.elpi │ ├── map_list_opt.elpi │ ├── mk-evar-meta.elpi │ ├── mu.mod │ ├── mu.sig │ ├── name_builtin.elpi │ ├── named_clauses00.elpi │ ├── named_clauses01.elpi │ ├── named_clauses02.elpi │ ├── namespaces00.elpi │ ├── namespaces01.elpi │ ├── namespaces02.elpi │ ├── namespaces03.elpi │ ├── nil_cons.elpi │ ├── notation.elpi │ ├── notation_error.elpi │ ├── oc_eta.elpi │ ├── patternunif.elpi │ ├── patternunif2.elpi │ ├── pcf │ │ ├── README │ │ ├── control.mod │ │ ├── control.sig │ │ ├── eval.mod │ │ ├── eval.sig │ │ ├── eval_test.mod │ │ ├── eval_test.sig │ │ ├── examples.mod │ │ ├── examples.sig │ │ ├── mono_test.mod │ │ ├── mono_test.sig │ │ ├── monoinfer.mod │ │ ├── monoinfer.sig │ │ ├── monotypes.sig │ │ ├── pcf.mod │ │ ├── pcf.sig │ │ ├── poly_test.mod │ │ ├── poly_test.sig │ │ ├── polyinfer.mod │ │ ├── polyinfer.sig │ │ ├── polytypes.sig │ │ ├── refl_syntax.mod │ │ ├── refl_syntax.sig │ │ ├── tailrec.mod │ │ ├── tailrec.sig │ │ ├── tr_test.mod │ │ ├── tr_test.sig │ │ ├── unifytypes.mod │ │ └── unifytypes.sig │ ├── pi.elpi │ ├── pi3.elpi │ ├── pi5.elpi │ ├── pm.elpi │ ├── pnf.elpi │ ├── polymorphic_variants.elpi │ ├── printer.elpi │ ├── progs │ │ ├── README │ │ ├── curry_test.mod │ │ ├── curry_test.sig │ │ ├── curry_transform.mod │ │ ├── curry_transform.sig │ │ ├── eval.mod │ │ ├── eval.sig │ │ ├── eval_basic.mod │ │ ├── eval_basic.sig │ │ ├── eval_examples.mod │ │ ├── eval_examples.sig │ │ ├── fp_types.sig │ │ ├── fp_vocab.sig │ │ ├── general_tr.mod │ │ ├── general_tr.sig │ │ ├── progs.mod │ │ ├── progs.sig │ │ ├── progs1.mod │ │ ├── progs1.sig │ │ ├── progs2.mod │ │ ├── progs2.sig │ │ ├── progs3.mod │ │ ├── progs3.sig │ │ ├── progs4.mod │ │ ├── progs4.sig │ │ ├── refl_syntax.mod │ │ ├── refl_syntax.sig │ │ ├── script1 │ │ ├── script2 │ │ ├── script3 │ │ ├── script4 │ │ ├── terms.mod │ │ ├── terms.sig │ │ ├── tr1_test.mod │ │ ├── tr1_test.sig │ │ ├── tr2_test.mod │ │ ├── tr2_test.sig │ │ ├── tr_recognizer.mod │ │ └── tr_recognizer.sig │ ├── queens.elpi │ ├── queens.mod │ ├── queens.sig │ ├── quote_syntax.elpi │ ├── random.elpi │ ├── reduce_cbn.elpi │ ├── reduce_cbn.mod │ ├── reduce_cbn.sig │ ├── reduce_cbv.elpi │ ├── reduce_cbv.mod │ ├── reduce_cbv.sig │ ├── restriction.elpi │ ├── restriction3.elpi │ ├── restriction4.elpi │ ├── restriction5.elpi │ ├── restriction6.elpi │ ├── rev.elpi │ ├── rev14.elpi │ ├── rev14.mod │ ├── rev14.sig │ ├── same_term.elpi │ ├── self_assignment.elpi │ ├── sepcomp1.ml │ ├── sepcomp2.ml │ ├── sepcomp3.ml │ ├── sepcomp4.ml │ ├── sepcomp5.ml │ ├── sepcomp6.ml │ ├── sepcomp7.ml │ ├── sepcomp8.ml │ ├── sepcomp9.ml │ ├── sepcomp_hover.ml │ ├── sepcomp_perf1.ml │ ├── sepcomp_perf2.ml │ ├── sepcomp_perf3.ml │ ├── sepcomp_perf4.ml │ ├── sepcomp_perf5.ml │ ├── sepcomp_template.ml │ ├── sepcomp_tyid.ml │ ├── sepcomp_tyid2.ml │ ├── set.elpi │ ├── set_ho.elpi │ ├── shorten.elpi │ ├── shorten2.elpi │ ├── shorten_aux.elpi │ ├── shorten_aux2.elpi │ ├── shorten_builtin.elpi │ ├── shorten_trie.elpi │ ├── spill-var.elpi │ ├── spill2.elpi │ ├── spill_and.elpi │ ├── spill_collision.elpi │ ├── spill_impl.elpi │ ├── spill_in_list.elpi │ ├── spill_lam.elpi │ ├── spill_or.elpi │ ├── spill_pi.elpi │ ├── spill_sigma.elpi │ ├── tc_ambiguous.elpi │ ├── toyml │ │ ├── ast.ml │ │ ├── dune.disabled │ │ ├── input │ │ ├── lexer.mll │ │ ├── output │ │ ├── parser.mly │ │ ├── pmap.ml │ │ ├── toyml.ml │ │ └── w.elpi │ ├── trace-w │ │ ├── hm.elpi │ │ └── main.elpi │ ├── trace.elab.json │ ├── trace.elpi │ ├── trace.json │ ├── trace2.elab.json │ ├── trace2.elpi │ ├── trace2.json │ ├── trace3.elab.json │ ├── trace3.elpi │ ├── trace3.json │ ├── trace4.elab.json │ ├── trace4.elpi │ ├── trace4.json │ ├── trace_chr.elab.json │ ├── trace_chr.elpi │ ├── trace_chr.json │ ├── trace_cut.elab.json │ ├── trace_cut.elpi │ ├── trace_cut.json │ ├── trace_findall.elab.json │ ├── trace_findall.elpi │ ├── trace_findall.json │ ├── trace_w.elab.json │ ├── trace_w.json │ ├── trail.elpi │ ├── trie.elpi │ ├── typeabbrv.elpi │ ├── typeabbrv1.elpi │ ├── typeabbrv10.elpi │ ├── typeabbrv11.elpi │ ├── typeabbrv12.elpi │ ├── typeabbrv13.elpi │ ├── typeabbrv14.elpi │ ├── typeabbrv15.elpi │ ├── typeabbrv2.elpi │ ├── typeabbrv3.elpi │ ├── typeabbrv4.elpi │ ├── typeabbrv5.elpi │ ├── typeabbrv6.elpi │ ├── typeabbrv7.elpi │ ├── typeabbrv8.elpi │ ├── typeabbrv9.elpi │ ├── uminus.elpi │ ├── unix.elpi │ ├── uvar_chr.elpi │ ├── var.elpi │ ├── variadic_declare_constraints.elpi │ ├── w.elpi │ ├── zebra.elpi │ ├── zebra.mod │ └── zebra.sig ├── suite │ ├── builtins.ml │ ├── correctness_FO.ml │ ├── correctness_HO.ml │ ├── dune │ ├── elpi_api.ml │ ├── elpi_api_performance.ml │ ├── elpi_specific.ml │ ├── performance_FO.ml │ ├── performance_HO.ml │ ├── suite.ml │ └── suite.mli ├── test.dummy.ml └── test.real.ml └── trace ├── ppx ├── dune └── trace_ppx.ml └── runtime ├── dune ├── runtime.ml └── runtime.mli /.gitattributes: -------------------------------------------------------------------------------- 1 | *.elpi linguist-language=prolog 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | .*.swp 3 | .merlin 4 | .vscode 5 | 6 | elpi.* 7 | 8 | data.csv 9 | data.csv.dat 10 | data.csv.plot 11 | data.csv.svg 12 | 13 | tests/sources/lyp/helena 14 | tests/sources/lyp/etc 15 | tests/sources/helena_elpi/helena 16 | tests/sources/helena_elpi/etc 17 | tests/test.exe 18 | 19 | vendor/*/ 20 | 21 | */merlinppx.exe 22 | 23 | _build 24 | _log 25 | 26 | docs/build 27 | docs/source 28 | -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | m = 120 2 | -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | ELPI is copyright 2014-2024 by: 2 | - Claudio Sacerdoti Coen 3 | - Enrico Tassi 4 | 5 | Patricia trees (elpi_ptmap.ml) and persistent arrays (part of Bl.ml) are 6 | copyright by Jean-Christophe Filliatre. 7 | 8 | We thank the following people for their contributions to ELPI: 9 | - Cvetan Dunchev 10 | - Ferruccio Guidi 11 | - Marco Maggesi 12 | - Davide Fissore 13 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/base/a.elpi: -------------------------------------------------------------------------------- 1 | type s num -> num. 2 | type zero num. 3 | pred ack i:num, i:num, o:num. 4 | ack zero N V :- !, V = (s N). 5 | ack M zero V :- !, (s M2) = M, ack M2 (s zero) V. 6 | ack M N V :- (s M2) = M, (s N2) = N, ack M N2 V2, ack M2 V2 V. 7 | main :- ack (s (s (s zero))) (s zero) V, print "V =" V. -------------------------------------------------------------------------------- /docs/base/index.rst: -------------------------------------------------------------------------------- 1 | .. Elpi documentation master file, created by 2 | sphinx-quickstart on Thu Jun 16 10:59:15 2022. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to Elpi's documentation! 7 | ================================ 8 | 9 | .. .. toctree: 10 | .. :maxdepth: 2 11 | .. :caption: Contents: 12 | .. 13 | .. about 14 | .. playground 15 | 16 | .. toctree:: 17 | :maxdepth: 2 18 | :caption: API: 19 | 20 | elpi 21 | elpi-option-legacy-parser 22 | 23 | -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name elpi_REPL) 3 | (public_name elpi) 4 | (libraries elpi elpi.parser ;memtrace 5 | ) 6 | (modules elpi_REPL) 7 | (package elpi) 8 | ) 9 | (env 10 | (dev 11 | (flags (:standard -w -9 -w -27 -warn-error -A)))) 12 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.8) 2 | (name elpi) 3 | (using menhir 2.0) 4 | -------------------------------------------------------------------------------- /src/compiler/determinacy_checker.mli: -------------------------------------------------------------------------------- 1 | (* elpi: embedded lambda prolog interpreter *) 2 | (* license: GNU Lesser General Public License Version 2.1 or later *) 3 | (* ------------------------------------------------------------------------- *) 4 | open Compiler_data 5 | open Type_checker 6 | 7 | (* returns if the clause is deterministic *) 8 | val check_clause : 9 | type_abbrevs:type_abbrevs -> 10 | types:TypingEnv.t -> 11 | unknown:env_undeclared -> 12 | ScopedTerm.t -> unit 13 | -------------------------------------------------------------------------------- /src/compiler/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name elpi_compiler) 3 | (public_name elpi.compiler) 4 | (preprocess (per_module 5 | ((pps ppx_deriving.std) compiler_data type_checker compiler determinacy_checker spilling))) 6 | (libraries re.str unix stdlib-shims elpi.parser elpi.util elpi.runtime) 7 | (modules compiler_data type_checker determinacy_checker compiler spilling) 8 | ) 9 | 10 | (test (name test_compiler_data) (libraries elpi.compiler) (modules test_compiler_data) (preprocess (pps ppx_deriving.std))) 11 | (test (name test_union_find) (libraries elpi.compiler) (modules test_union_find) (preprocess (pps ppx_deriving.std))) 12 | (test (name test_type_checker) (libraries elpi.compiler) (modules test_type_checker) (preprocess (pps ppx_deriving.std))) 13 | 14 | (env 15 | (dev 16 | (flags (:standard -w -9 -w -27 -warn-error -A))) 17 | (fatalwarnings 18 | (flags (:standard -w -9 -w -27 -warn-error +A)))) 19 | -------------------------------------------------------------------------------- /src/compiler/spilling.mli: -------------------------------------------------------------------------------- 1 | (* elpi: embedded lambda prolog interpreter *) 2 | (* license: GNU Lesser General Public License Version 2.1 or later *) 3 | (* ------------------------------------------------------------------------- *) 4 | 5 | val main : type_abbrevs:Compiler_data.TypeAssignment.type_abbrevs -> types:Compiler_data.TypingEnv.t -> Compiler_data.ScopedTerm.t -> Compiler_data.ScopedTerm.t 6 | -------------------------------------------------------------------------------- /src/compiler/test_union_find.ml: -------------------------------------------------------------------------------- 1 | open Elpi_util.Union_find 2 | 3 | module M = Make (Elpi_util.Util.Int) 4 | 5 | open M 6 | 7 | let _ = 8 | (* From https://fr.wikipedia.org/wiki/Union-find#/media/Fichier:Dsu_disjoint_sets_final.svg *) 9 | let uf = ref empty in 10 | let update uf (_,act) = uf := act in 11 | let union uf a b = update uf (union !uf a ~canon:b) in 12 | 13 | (* Partition avec 4 classes disjointes obtenue après 14 | Union(1, 2), Union(3, 4), Union(2, 5), Union(1, 6) et Union(2, 8). *) 15 | union uf 1 2; 16 | union uf 3 4; 17 | union uf 2 5; 18 | 19 | let uf1 = ref !uf in 20 | 21 | union uf 1 6; 22 | union uf 3 1; 23 | assert (roots !uf |> M.KeySet.cardinal = 1); 24 | (* The cloned table is not impacted by the modification in uf *) 25 | assert (roots !uf1 |> M.KeySet.cardinal = 2); 26 | union uf1 7 8; 27 | assert (roots !uf1 |> M.KeySet.cardinal = 3); 28 | assert (roots !uf |> M.KeySet.cardinal = 1) 29 | -------------------------------------------------------------------------------- /src/dune.config: -------------------------------------------------------------------------------- 1 | (dirs :standard \ legacy_parser) 2 | -------------------------------------------------------------------------------- /src/parser/gen_token_precedence.ml: -------------------------------------------------------------------------------- 1 | open Elpi_lexer_config.Lexer_config 2 | 3 | let pp_mehir_fixity fmt = function 4 | | Infix | Postfix | Prefix -> Format.fprintf fmt "nonassoc" 5 | | Infixl -> Format.fprintf fmt "left" 6 | | Infixr -> Format.fprintf fmt "right" 7 | 8 | let pp_token_names fmt l = 9 | l |> List.iter (function 10 | | Fixed { token; _ } -> Format.fprintf fmt "%s " token 11 | | Extensible { token; _ } -> Format.fprintf fmt "%s " token) 12 | 13 | let () = 14 | Format.printf "%%right BIND\n"; 15 | mixfix_symbols |> List.iter (fun { fixity; tokens; _ } -> 16 | Format.printf "%%%a %a\n" pp_mehir_fixity fixity pp_token_names tokens); 17 | Format.printf "%%%%\n" 18 | -------------------------------------------------------------------------------- /src/parser/token_precedence.mly: -------------------------------------------------------------------------------- 1 | %right BIND 2 | %nonassoc VDASH QDASH 3 | %right OR 4 | %right DDARROW 5 | %right DDARROWBANG 6 | %right CONJ CONJ2 7 | %right ARROW 8 | %right DARROW 9 | %nonassoc EQ EQ2 FAMILY_LT FAMILY_GT IS 10 | %right CONS 11 | %nonassoc FAMILY_TICK 12 | %left FAMILY_EXP FAMILY_PLUS MINUS MINUSr MINUSi MINUSs 13 | %left FAMILY_TIMES SLASH DIV MOD 14 | %right FAMILY_MINUS 15 | %nonassoc FAMILY_BTICK 16 | %right FAMILY_EQ 17 | %right FAMILY_OR 18 | %right FAMILY_AND 19 | %left FAMILY_SHARP 20 | %nonassoc FAMILY_TILDE 21 | %nonassoc FAMILY_QMARK 22 | %% 23 | -------------------------------------------------------------------------------- /src/runtime/bl.mli: -------------------------------------------------------------------------------- 1 | (* elpi: embedded lambda prolog interpreter *) 2 | (* license: GNU Lesser General Public License Version 2.1 or later *) 3 | (* ------------------------------------------------------------------------- *) 4 | 5 | (* functional lists with O(1) rcons *) 6 | 7 | type 'a t 8 | val pp : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit 9 | val show : (Format.formatter -> 'a -> unit) -> 'a t -> string 10 | 11 | val empty : unit -> 'a t 12 | val cons : 'a -> 'a t -> 'a t 13 | val rcons : 'a -> 'a t -> 'a t 14 | 15 | val replace : ('a -> bool) -> 'a -> 'a t -> 'a t 16 | 17 | (* [insert f x l] inserts before y in l if f y > 0 *) 18 | val insert : ('a -> int) -> 'a -> 'a t -> 'a t 19 | val remove : ('a -> bool) -> 'a t -> 'a t 20 | 21 | type 'a scan 22 | val to_scan : 'a t -> 'a scan 23 | val is_empty : 'a scan -> bool 24 | val next : 'a scan -> 'a * 'a scan 25 | val to_list : 'a scan -> 'a list 26 | val of_list : 'a list -> 'a scan 27 | val length : 'a scan -> int 28 | 29 | -------------------------------------------------------------------------------- /src/runtime/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name elpi_runtime) 3 | (public_name elpi.runtime) 4 | (preprocess (per_module 5 | ((pps ppx_deriving.std) data discrimination_tree bl) 6 | ((pps ppx_deriving.std elpi.trace.ppx -- --cookie "elpi_trace=\"true\"") runtime) 7 | ((pps ppx_deriving.std elpi.trace.ppx -- --cookie "elpi_trace=\"false\"") runtime_trace_off) 8 | )) 9 | (libraries re.str unix stdlib-shims elpi.parser elpi.util) 10 | (modules data ptmap discrimination_tree bl runtime_trace_off runtime) 11 | ) 12 | 13 | (test (name test_discrimination_tree) (libraries elpi.runtime) (modules test_discrimination_tree) (preprocess (pps ppx_deriving.std))) 14 | (test (name test_bl) (libraries elpi.runtime) (modules test_bl) (preprocess (pps ppx_deriving.std))) 15 | (test (name test_lex) (libraries elpi.runtime) (modules test_lex) (preprocess (pps ppx_deriving.std))) 16 | -------------------------------------------------------------------------------- /src/runtime/runtime_trace_off.ml: -------------------------------------------------------------------------------- 1 | runtime.ml -------------------------------------------------------------------------------- /src/runtime/runtime_trace_off.mli: -------------------------------------------------------------------------------- 1 | runtime.mli -------------------------------------------------------------------------------- /src/runtime/test_bl.ml: -------------------------------------------------------------------------------- 1 | open Elpi_runtime.Bl 2 | let size = min (Sys.max_array_length / 2 - 1) 9999999 3 | let test_build () = 4 | Gc.minor (); Gc.major (); 5 | 6 | let t0 = Unix.gettimeofday () in 7 | let rec aux n acc = 8 | (* Format.eprintf "bl before adding %d = %a\n" n pp acc; *) 9 | if n = 0 then acc else aux (n-1) (rcons n acc) in 10 | let r1 = aux size (empty ()) in 11 | let t1 = Unix.gettimeofday () in 12 | 13 | Gc.minor (); Gc.major (); 14 | 15 | let t2 = Unix.gettimeofday () in 16 | let rec aux n acc = 17 | if n = 0 then acc else aux (n-1) (n :: acc) in 18 | let r2 = List.rev @@ aux size [] in 19 | let t3 = Unix.gettimeofday () in 20 | 21 | Format.eprintf "build: bl=%4f l=%4f\n" (t1-.t0) (t3-.t2); 22 | (* Format.eprintf "bl=%a\n" pp r1; *) 23 | r1, r2 24 | ;; 25 | 26 | let _ = test_build () -------------------------------------------------------------------------------- /src/runtime/test_lex.ml: -------------------------------------------------------------------------------- 1 | open Elpi_runtime.Runtime 2 | 3 | let rec sorted = function 4 | | [] -> true 5 | | [ _ ] -> true 6 | | x :: (y :: _ as l) -> 7 | let r = lex_insertion x y < 0 in 8 | if not r then Format.(eprintf "Not sorted [%a] [%a]\n" (pp_print_list pp_print_int) x (pp_print_list pp_print_int) y); 9 | r && sorted l 10 | 11 | let () = 12 | assert (lex_insertion [] [] = 0); 13 | 14 | (* test 1 *) 15 | assert( sorted [ [-1] ; [0] ; [1;-1]; [1;-2]; [1] ; [1;2] ; [1;1] ; [2] ; ]); 16 | assert( sorted [ [-1] ; [0] ; [1;-1]; [1;-2]; [1;-3]; [1] ; [1;2] ; [1;1] ; [2] ; ]); 17 | 18 | assert( sorted [ [1;-1]; [2;-2]; ]); 19 | assert( sorted [ [-1]; [0]; [1] ]); 20 | assert( sorted [ [-2]; [-1]; [0] ]); 21 | assert( sorted [ [241]; [242;-1]; [243] ]); 22 | 23 | assert(lex_insertion[243] [242;-1] > 0); 24 | assert(lex_insertion [242;-1] [241] > 0); 25 | assert(lex_insertion [241] [242;-1] < 0); 26 | 27 | assert(lex_insertion [242;0;9] [242;-1;9] > 0); 28 | assert(lex_insertion [242;0;9] [242;-1;8] > 0); 29 | ;; 30 | 31 | -------------------------------------------------------------------------------- /src/utils/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name elpi_util) 3 | (public_name elpi.util) 4 | (preprocess (per_module 5 | ((pps ppx_deriving.std) util union_find))) 6 | (libraries unix re.str) 7 | (modules util union_find)) 8 | -------------------------------------------------------------------------------- /src/utils/union_find.mli: -------------------------------------------------------------------------------- 1 | (* elpi: embedded lambda prolog interpreter *) 2 | (* license: GNU Lesser General Public License Version 2.1 or later *) 3 | (* ------------------------------------------------------------------------- *) 4 | 5 | open Util 6 | 7 | module type S = sig 8 | include Show 9 | include ShowKey 10 | module KeySet : Util.Set.S with type elt = key 11 | 12 | val empty : t 13 | val is_empty : t -> bool 14 | val find : t -> key -> key 15 | val find_class : t -> key -> key * KeySet.t 16 | val union : t -> key -> canon:key -> key option * t 17 | val merge : t -> t -> t 18 | val roots : t -> KeySet.t 19 | (* The first higher-order function should be injective otherwise the UF is broken *) 20 | val mapi : (key -> key) -> t -> t 21 | end 22 | 23 | module Make (O : Map.OrderedType) : S with type key = O.t 24 | -------------------------------------------------------------------------------- /tests/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name test) 3 | (modules test) 4 | (optional) 5 | (promote) 6 | (libraries 7 | (select test.ml from 8 | (test_suite ANSITerminal cmdliner str unix -> test.real.ml) 9 | (-> test.dummy.ml))) 10 | ) 11 | (env 12 | (dev 13 | (flags (:standard -w -9 -w -32 -w -27 -w -6 -w -37 -warn-error -A))) 14 | (fatalwarnings 15 | (flags (:standard -w -9 -w -32 -w -27 -w -6 -w -37 -warn-error +A)))) 16 | -------------------------------------------------------------------------------- /tests/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.0) 2 | -------------------------------------------------------------------------------- /tests/sources/GH_issue_19.elpi: -------------------------------------------------------------------------------- 1 | type transl any -> prop. 2 | type p any -> int. 3 | type pp any -> prop. 4 | transl (y \ _\ M y) :- % strip the hole 5 | P = (w \ p w), 6 | transl (z \ M (P z)). 7 | 8 | transl (x \ pp (X x)). 9 | 10 | % with a hole 11 | pred test1. 12 | test1 :- transl (x0 \ _ \ pp (p x0)). 13 | 14 | % with no hole 15 | pred test2. 16 | test2 :- transl (x0 \ pp (p x0)). 17 | 18 | main :- test1, test2. 19 | -------------------------------------------------------------------------------- /tests/sources/accumulate_twice1.elpi: -------------------------------------------------------------------------------- 1 | pred doomed o:int. 2 | accumulate accumulated. 3 | accumulate accumulated. 4 | main :- 5 | doomed 100. -------------------------------------------------------------------------------- /tests/sources/accumulate_twice2.elpi: -------------------------------------------------------------------------------- 1 | accumulate accumulated. 2 | namespace other { accumulate accumulated. } 3 | main :- 4 | doomed 100, 5 | other.doomed 100. -------------------------------------------------------------------------------- /tests/sources/accumulated.elpi: -------------------------------------------------------------------------------- 1 | pred doomed i:int. 2 | doomed 0 :- fail. 3 | doomed N :- N > 0, M is N - 1, doomed M. -------------------------------------------------------------------------------- /tests/sources/ackermann.elpi: -------------------------------------------------------------------------------- 1 | % ack (s zero) (s zero) V. yields V = s(s(s(zero))) = 3 2 | % ack (s (s zero)) (s (s zero)) V. yields V = s(s...(s zero)) = 7 3 | % ack (s (s (s zero))) (s zero) V. yields V = s(s...(s zero)) = 13 4 | % ack (s (s (s zero))) (s (s zero)) V. yields V = .... = 29 5 | % ack (s (s (s (s zero)))) (s zero) V. yields nothing 6 | 7 | % ack +int +int -int 8 | % ack(0, N, V) :- !, V is N + 1. 9 | % ack(M, 0, V) :- !, M2 is M - 1, ack(M2, 1, V). 10 | % ack(M, N, V) :- M2 is M - 1, N2 is N - 1, ack(M, N2, V2), ack(M2, V2, V). 11 | 12 | 13 | kind nat type. 14 | type s nat -> nat. 15 | type zero nat. 16 | 17 | pred ack i:nat, i:nat, o:nat. 18 | ack zero N V :- !, V = (s N). 19 | 20 | ack M zero V :- !, (s M2) = M, ack M2 (s zero) V. 21 | 22 | ack M N V :- (s M2) = M, (s N2) = N, ack M N2 V2, ack M2 V2 V. 23 | 24 | main :- ack (s (s (s zero))) (s zero) V. 25 | -------------------------------------------------------------------------------- /tests/sources/asclause.elpi: -------------------------------------------------------------------------------- 1 | 2 | kind tm type. 3 | type lam (tm -> tm) -> tm. 4 | 5 | pred hard i:tm. 6 | hard (lam x\ _ as P) :- print P. 7 | 8 | pred simple i:int. 9 | simple (1 as P) :- print P. 10 | 11 | main :- 12 | simple 1, hard (lam x\ x). 13 | -------------------------------------------------------------------------------- /tests/sources/bad_index.elpi: -------------------------------------------------------------------------------- 1 | :index (1 1) "Map" 2 | pred foo i:int, i:int. 3 | -------------------------------------------------------------------------------- /tests/sources/beta.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | type f tm -> tm -> tm. 3 | type a, b tm. 4 | 5 | main :- X = (x\ y\ f x y), X a b = f a b. 6 | -------------------------------------------------------------------------------- /tests/sources/block.elpi: -------------------------------------------------------------------------------- 1 | namespace xxx { 2 | foo. 3 | -------------------------------------------------------------------------------- /tests/sources/bug-256.elpi: -------------------------------------------------------------------------------- 1 | pred u o:(int -> int). 2 | u (y\y). 3 | 4 | main :- 5 | print "-----------", 6 | t1, 7 | print "-----------", 8 | t2, 9 | t3, 10 | true. 11 | 12 | pred p o:any. 13 | pred q o:any. 14 | type f int -> prop. 15 | type g any -> any -> any -> int. 16 | 17 | pred t1. 18 | t1 :- pi x\ u (y\ X x y), std.assert! (X 1 2 = 2) "bug". 19 | 20 | pred t2. 21 | t2 :- 22 | (pi X\ p ( a\f (X a))) => pi x y\ p ( a\f (g x y a)). 23 | 24 | pred t3. 25 | t3 :- 26 | (pi X\ q ( a\b\c\d\f (X a))) => pi x y\ q ( a\b\c\d\f (g x y a)). 27 | -------------------------------------------------------------------------------- /tests/sources/bug_226.elpi: -------------------------------------------------------------------------------- 1 | 2 | kind term type. 3 | type fun (term -> term) -> term. 4 | pred f o:(term -> term) o:term. 5 | f R (fun d\ R d). 6 | %f R N :- N = (fun d\ R d). 7 | 8 | 9 | pred foo o:(term -> term) o:term. 10 | foo R N :- 11 | pi d\ 12 | f R N. 13 | 14 | main :- 15 | foo R N, N == fun x\R x. -------------------------------------------------------------------------------- /tests/sources/chr-scope-change-failure.elpi: -------------------------------------------------------------------------------- 1 | constraint foo good bad { 2 | rule \ ([C1,C2] :> D ?- foo G B) <=> ([] :> D ?- foo G B). 3 | } 4 | 5 | pred good i:int. 6 | pred bad i:int. 7 | pred foo i:int, i:int. 8 | foo A B :- print A B, good A, bad B. 9 | 10 | main :- 11 | pi x y\ 12 | good x => bad y => declare_constraint (foo x y) []. -------------------------------------------------------------------------------- /tests/sources/chr-scope-change.elpi: -------------------------------------------------------------------------------- 1 | constraint foo good bad { 2 | rule \ (L :> D ?- foo G B) | (std.rev L L1) <=> (L1 :> D ?- foo G B). 3 | } 4 | 5 | pred good i:int. 6 | pred bad i:int. 7 | pred foo i:int, i:int. 8 | foo A B :- print A B, good A, bad B. 9 | 10 | main :- 11 | pi x y\ 12 | good x => bad y => declare_constraint (foo x y) []. -------------------------------------------------------------------------------- /tests/sources/chr-scope.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | type f tm -> tm -> tm. 3 | 4 | pred move i:tm, i:tm, i:tm -> tm, o:tm -> tm. 5 | move A B (x\f B x) (x\f A x). 6 | 7 | pred c i:tm, i:tm -> tm. 8 | 9 | constraint c { 10 | rule (E :> G ?- c (uvar X [A]) T1) \ (F :> _ ?- c (uvar X [B]) T2) 11 | | (move A B T2 T2') <=> (E :> G ?- T1 = T2'). 12 | } 13 | 14 | main :- 15 | pi x\ 16 | declare_constraint (c (X x) (y\f x y)) [X x], 17 | pi z\ 18 | declare_constraint (c (X x) (y\f x y)) [X x]. -------------------------------------------------------------------------------- /tests/sources/chrGCD.elpi: -------------------------------------------------------------------------------- 1 | pred gcd i:int, i:group. 2 | kind group type. 3 | type group-1 group. 4 | type group-2 group. 5 | 6 | gcd A (uvar as B) :- !, declare_constraint (gcd A B) [B]. 7 | 8 | % assert result is OK 9 | gcd 11 group-1 :- print "group 1 solved". 10 | gcd 7 group-2 :- print "group 2 solved". 11 | 12 | main :- gcd 99 X, gcd 66 X, gcd 14 Y, gcd 22 X, gcd 77 Y, 13 | % we then force a resumption to check only GCDs are there 14 | X = group-1, Y = group-2. 15 | 16 | constraint gcd { 17 | rule (gcd A _) \ (gcd B _) | (A = B). 18 | rule (gcd A _) \ (gcd B X) | (A < B) <=> (C is (B - A), gcd C X). 19 | } 20 | 21 | -------------------------------------------------------------------------------- /tests/sources/chr_nokey.elpi: -------------------------------------------------------------------------------- 1 | type test int -> prop. 2 | 3 | main :- declare_constraint (test 1) [_], declare_constraint (test 2) [_]. 4 | 5 | constraint test { 6 | 7 | :name "fst" 8 | rule (test 1) \ (test 2). 9 | 10 | rule (test 2) <=> fail. 11 | 12 | } 13 | -------------------------------------------------------------------------------- /tests/sources/chr_nokey2.elpi: -------------------------------------------------------------------------------- 1 | type foo prop. 2 | type bar any -> prop. 3 | 4 | main :- declare_constraint foo [], declare_constraint (bar X) [], X. 5 | 6 | constraint foo bar { rule foo (bar _) <=> false. rule (bar X) <=> (X = true). } 7 | 8 | -------------------------------------------------------------------------------- /tests/sources/chr_not_clique.elpi: -------------------------------------------------------------------------------- 1 | constraint a { 2 | 3 | rule b. 4 | 5 | } -------------------------------------------------------------------------------- /tests/sources/chr_sem.elpi: -------------------------------------------------------------------------------- 1 | type a, b, c, d prop. 2 | main :- declare_constraint a [_], 3 | declare_constraint b [_], 4 | declare_constraint b [_], 5 | declare_constraint d [_]. 6 | 7 | constraint a b c d { 8 | rule a (d) \ b b <=> (print c, declare_constraint c [_]). 9 | rule c c <=> fail. 10 | 11 | } 12 | -------------------------------------------------------------------------------- /tests/sources/conj2.elpi: -------------------------------------------------------------------------------- 1 | pred test1. 2 | pred test2. 3 | main :- test1, test2. 4 | 5 | test1 :- true & true & true. 6 | test2 :- X = [true & true, false], std.length X 2. -------------------------------------------------------------------------------- /tests/sources/crypt.sig: -------------------------------------------------------------------------------- 1 | sig crypt. 2 | 3 | kind i type. 4 | kind mylist type -> type. 5 | 6 | type null i. 7 | type s i -> i. 8 | type xnil mylist i. 9 | type xcons i -> mylist i -> mylist i. 10 | type crypt mylist i -> o. 11 | type sum2 mylist i -> mylist i -> mylist i -> o. 12 | type sum2_aux mylist i -> mylist i -> i -> mylist i -> o. 13 | type mult mylist i -> i -> mylist i -> o. 14 | type mult_aux mylist i -> i -> i -> mylist i -> o. 15 | type plus i -> i -> i -> o. 16 | type prod i -> i -> i -> o. 17 | type divv i -> i -> i -> o. 18 | type modd i -> i -> i -> o. 19 | type less i -> i -> o. 20 | type zero mylist i -> o. 21 | type is_even i -> o. 22 | type is_odd i -> o. 23 | type is_lefteven i -> o. 24 | type digit i -> o. 25 | type even i -> o. 26 | type odd i -> o. 27 | type lefteven i -> o. 28 | type main o. 29 | type once o. 30 | type iter i -> o. 31 | type exp i -> i -> i -> o. 32 | type check mylist i -> mylist i -> o. 33 | -------------------------------------------------------------------------------- /tests/sources/ctx_loading.elpi: -------------------------------------------------------------------------------- 1 | constraint a b c d1 d2 d3 d11 d22 d33 { 2 | rule (C ?- d1 X) | (print C) <=> (C ?- declare_constraint (d11 X) [X]). 3 | rule (C ?- d2 X) | (print C) <=> (C ?- declare_constraint (d22 X) [X]). 4 | rule (C ?- d3 X) | (print C) <=> (C ?- declare_constraint (d33 X) [X]). 5 | rule \ (C ?- d1 X) (C ?- d11 X). 6 | rule \ (C ?- d2 X) (C ?- d22 X). 7 | rule \ (C ?- d3 X) (C ?- d33 X). 8 | } 9 | type p prop -> prop. 10 | type a prop. 11 | type b prop. 12 | type c prop. 13 | type d1, d2, d3, d11, d22, d33 prop -> prop. 14 | 15 | main :- 16 | (p b ==> p a ==> p W), !, W = a, 17 | ([p a, p b] ==> p Y), !, Y = a, 18 | ((p a, p b) ==> p Z), !, Z = a, 19 | ([a, b, c] ==> declare_constraint (d1 X) [X]), 20 | (c ==> b ==> a ==> declare_constraint (d2 X) [X]), 21 | ((a, b, c) => declare_constraint (d3 X) [X]), 22 | X = a. 23 | 24 | -------------------------------------------------------------------------------- /tests/sources/cut.elpi: -------------------------------------------------------------------------------- 1 | /* To test: query q X. The only answer should be X = ok. */ 2 | 3 | kind tm type. 4 | type two, three, four, ok, ko tm. 5 | 6 | type a, b, c, q tm -> prop. 7 | 8 | q X :- a X. 9 | q ok. 10 | 11 | a ko :- b Y, !, c Y. 12 | a two. 13 | 14 | b three. 15 | b four. 16 | 17 | c four. 18 | 19 | main :- q X, X = ok. 20 | -------------------------------------------------------------------------------- /tests/sources/cut2.elpi: -------------------------------------------------------------------------------- 1 | /* To test run q X; the only expected result is X=ok. 2 | This is different from the brain-damaged semantics of Teyjus 3 | and consistent with the implicit declaration 4 | ; A B :- A. 5 | ; A B :- B 6 | */ 7 | kind i type. 8 | type one i. 9 | type x i -> diagnostic -> prop. 10 | type two i. 11 | type q diagnostic -> prop. 12 | type ko2 diagnostic. 13 | type ko1 diagnostic. 14 | type e diagnostic -> prop. 15 | type c i -> prop. 16 | 17 | q X :- c Y, !, x Y X ; e X. 18 | q ok. 19 | 20 | c one. 21 | c two. 22 | 23 | x two ko1. 24 | 25 | e ko2. 26 | 27 | main :- q X, X = ok. 28 | -------------------------------------------------------------------------------- /tests/sources/cut3.elpi: -------------------------------------------------------------------------------- 1 | % Test with q X; should yield X=ok 2 | 3 | kind i type. 4 | type ko i. 5 | type ok i. 6 | type q i -> prop. 7 | type c i -> prop. 8 | type b prop. 9 | type a i -> prop. 10 | 11 | q X :- a X, b, c X. 12 | 13 | a ko. 14 | a ok. 15 | 16 | b :- !. 17 | b. 18 | 19 | c ok. 20 | 21 | main :- q X, X = ok. 22 | -------------------------------------------------------------------------------- /tests/sources/cut4.elpi: -------------------------------------------------------------------------------- 1 | % Test: main. Should not fail. 2 | 3 | main :- !. 4 | -------------------------------------------------------------------------------- /tests/sources/cut5.elpi: -------------------------------------------------------------------------------- 1 | /* To test: query q X. The only answer should be X = ok. */ 2 | 3 | kind i type. 4 | type ko i. 5 | type ok i. 6 | type four i. 7 | type two i. 8 | type three i. 9 | type q i -> prop. 10 | type d i -> prop. 11 | type c i -> prop. 12 | type b i -> prop. 13 | type a i -> prop. 14 | 15 | q X :- a X. 16 | q ok. 17 | a ko :- b Y, !, d Z, !, c Z. 18 | a two. 19 | b three. 20 | b four. 21 | c four. 22 | d three. 23 | d four. 24 | main :- q X, X = ok. 25 | -------------------------------------------------------------------------------- /tests/sources/cut6.elpi: -------------------------------------------------------------------------------- 1 | % q X should yield X=ok 2 | kind i type. 3 | type ko i. 4 | type ok i. 5 | type q i -> prop. 6 | type c i -> prop. 7 | type b i -> prop. 8 | type a i -> prop. 9 | 10 | q X :- a X, !. 11 | q X :- b X. 12 | a X :- c X, !. 13 | c ok. 14 | c ko. 15 | b ko. 16 | main :- q X, X = ok. 17 | -------------------------------------------------------------------------------- /tests/sources/deep_indexing.elpi: -------------------------------------------------------------------------------- 1 | % select should only find 2 clauses (the last 2) since indexing at level 3 drops the others 2 | % ./elpi -test tests/sources/deep_indexing.elpi -no-tc -trace-on -trace-at run 1 300 -trace-only select 3 | 4 | kind term type. 5 | type f term -> term. 6 | type g term. 7 | 8 | :index(3) 9 | pred find i:term. 10 | find g. 11 | find (f g). 12 | find (f (f g)). 13 | find (f (f (f g))). 14 | find (f (f (f (f g)))). 15 | 16 | 17 | main :- find (f (f (f g))). 18 | -------------------------------------------------------------------------------- /tests/sources/discard.elpi: -------------------------------------------------------------------------------- 1 | type foo int. 2 | type bar int. 3 | main :- 4 | foo = _, 5 | _ = 4, 6 | _ = "", 7 | _ = _, 8 | _Foo = bar, 9 | pi x \ _Foo = x. 10 | -------------------------------------------------------------------------------- /tests/sources/dt.elpi: -------------------------------------------------------------------------------- 1 | :index (12) % DT is on 2 | pred f i:list int. 3 | 4 | pred mk-index i:int, i:(pred i:list int), o:list prop. 5 | mk-index 0 _ []. 6 | mk-index N P [C|CL] :- N > 0, N1 is N - 1, mk-clause P 10 [N] C, mk-index N1 P CL. 7 | 8 | pred mk-clause i:(pred i:list int), i:int, i:list int, o:prop. 9 | mk-clause P 0 X (P X). 10 | mk-clause P N ACC C :- N > 0, N1 is N - 1, 11 | mk-clause P N1 [N|ACC] C. 12 | 13 | pred repeat i:int, i:prop. 14 | repeat 0 _. 15 | repeat N P :- N > 0, N1 is N - 1, P, !, repeat N1 P. 16 | 17 | main :- 18 | mk-index 100 f CL1, 19 | !, 20 | CL1 => std.do! [ 21 | std.time (repeat 300000 (f [1,2,3,4,5,6,7,8,9,10,1])) TFast, 22 | std.time (repeat 300000 (f [1,2,3,4,5,6,7,8,9,10,100])) TSlow, 23 | print "DT=" TFast, 24 | print "PT=" TSlow, 25 | ]. 26 | -------------------------------------------------------------------------------- /tests/sources/dt_bench.elpi: -------------------------------------------------------------------------------- 1 | kind tree type. 2 | type node list tree -> tree. 3 | type leaf int -> tree. 4 | 5 | pred width o:int. 6 | width 5. 7 | 8 | pred mkt i:int, o:tree. 9 | mkt 0 (leaf N) :- !, random.int 100 N. 10 | % mkt M (node [leaf M|L]) :- M1 is M - 1, std.iota {random.int {width}} L1, std.map L1 (_\mkt M1) L. 11 | mkt M (node [leaf M|L]) :- M1 is M - 1, std.iota {random.int {width}} L1, std.map L1 (_\r\(mkt M1 r )) L. % hard fail 12 | % mkt M (node [leaf M|L]) :- M1 is M - 1, std.iota {random.int {width}} L1, std.map L1 (_\r\mkt M1 r) L. % bad call, not functional 13 | 14 | :index (5) "DTree" 15 | pred p i:tree. 16 | 17 | pred iter i:int, i:prop. 18 | iter 0 _ :- !. 19 | iter N P :- P, !, M is N - 1, iter M P. 20 | 21 | main :- 22 | print "a", 23 | mkt 6 T, print "b", mkt 6 T1, 24 | p T ==> std.time (iter 300000 (p T)) Time1, 25 | print "match" Time1, 26 | p T ==> std.time (iter 300000 (p T1 ; true)) Time2, 27 | print "no match" Time2. 28 | -------------------------------------------------------------------------------- /tests/sources/dt_bug272.elpi: -------------------------------------------------------------------------------- 1 | :index(1 1) 2 | pred map2 i:list A, i:list B, i:(pred i:A, i:B, o:C), o:list C. 3 | map2 [] [] _ []. 4 | map2 [A|As] [B|Bs] F [C|Cs] :- F A B C, map2 As Bs F Cs. 5 | 6 | pred any_list i:int, o:list int. 7 | any_list 0 [] :- !. 8 | any_list N [N|L] :- any_list {calc (N - 1)} L. 9 | 10 | pred any_pred i:int, i:int, o:int. 11 | any_pred A B R :- R is A + B. 12 | 13 | pred test i:int, o:list int. 14 | test N R :- any_list N L, map2 L L any_pred R. 15 | 16 | pred loop i:int, i:int. 17 | loop N N :- !. 18 | loop N M :- 19 | test N _, 20 | N1 is N + 1, 21 | loop N1 M. 22 | 23 | main :- loop 1 100. -------------------------------------------------------------------------------- /tests/sources/dt_bug323.elpi: -------------------------------------------------------------------------------- 1 | kind term type. 2 | type prod string -> term -> term. 3 | 4 | :index (3) 5 | pred f o:term, o:int. 6 | f (prod _ _) 1 :- print "AA". 7 | f X 2 :- print "BB". 8 | 9 | main :- 10 | std.findall (f _ _) L, 11 | std.assert! ({std.length L} = 2) "Mh". 12 | -------------------------------------------------------------------------------- /tests/sources/dt_empty_list.elpi: -------------------------------------------------------------------------------- 1 | :index (1) "DTree" 2 | pred p o:list int. 3 | p []. 4 | p [_|_]. 5 | 6 | main :- 7 | p _, 8 | p [], 9 | p [_|_]. -------------------------------------------------------------------------------- /tests/sources/dt_max_depths.elpi: -------------------------------------------------------------------------------- 1 | kind term type. 2 | type app list term -> term. 3 | type t term. 4 | type prod term -> term -> term. 5 | 6 | 7 | :index (100 100) 8 | pred p o:term, o:term. 9 | 10 | 11 | :index (3) 12 | pred q o:term. 13 | 14 | :index (2) 15 | pred r o:term. 16 | 17 | 18 | % Instances are loaded locally to get the correct printing in 19 | % the trace 20 | main :- 21 | % depths: 2 1 1 3 2 3 22 | (p (app[t | _]) _ => p _ (app[app[t] | _]) => p _ _), 23 | % with deep terms 24 | % depths: 3 (capped by the index) 3 25 | (q (prod t (prod t (prod t (prod t (prod t t))))) => q _), 26 | % with lists 27 | % depths: 2 (capped by the index) 2 28 | (r (app [app [app [ app[app[t]]]]]) => r _) 29 | . 30 | -------------------------------------------------------------------------------- /tests/sources/dt_multiparam1.elpi: -------------------------------------------------------------------------------- 1 | % The indexing with trie is used and returns only 2 | % one matching clause 3 | :index (1 1) 4 | pred p o:int, o:int. 5 | 6 | pred build_p i:int, i:int, i:int, o:list prop. 7 | build_p _ 0 0 [p 0 0] :- !. 8 | build_p Mem X 0 [p X 0 | TL] :- 9 | X > 0, X' is X - 1, 10 | build_p Mem X' Mem TL. 11 | build_p Mem X Y [p X Y | TL] :- 12 | Y > 0, Y' is Y - 1, 13 | build_p Mem X Y' TL. 14 | 15 | main :- 16 | N = 100, 17 | build_p N N N L, 18 | L => std.time (p 0 0) T, 19 | print T. -------------------------------------------------------------------------------- /tests/sources/dt_multiparam2.elpi: -------------------------------------------------------------------------------- 1 | % The indexing with trie is used and returns only 2 | % one matching clause 3 | :index (1 1) 4 | pred p o:int, o:int. 5 | 6 | pred build_p i:int, i:int, i:int, o:list prop. 7 | build_p _ 0 0 [p 0 0] :- !. 8 | build_p Mem X 0 [p X 0 | TL] :- 9 | X > 0, X' is X - 1, 10 | build_p Mem X' Mem TL. 11 | build_p Mem X Y [p X Y | TL] :- 12 | Y > 0, Y' is Y - 1, 13 | build_p Mem X Y' TL. 14 | 15 | main :- 16 | N = 100, 17 | build_p N N N L, 18 | L => std.time (p 0 X) T, 19 | print T. -------------------------------------------------------------------------------- /tests/sources/dt_multiparam3.elpi: -------------------------------------------------------------------------------- 1 | % The indexing with trie is used and returns no clauses 2 | :index (1 1) 3 | pred p i:int, o:int. 4 | 5 | pred build_p i:int, i:int, i:int, o:list prop. 6 | build_p _ 0 0 [p 0 0] :- !. 7 | build_p Mem X 0 [p X 0 | TL] :- 8 | X > 0, X' is X - 1, 9 | build_p Mem X' Mem TL. 10 | build_p Mem X Y [p X Y | TL] :- 11 | Y > 0, Y' is Y - 1, 12 | build_p Mem X Y' TL. 13 | 14 | pred ground o:A. 15 | % :untyped 16 | ground X. 17 | 18 | main :- 19 | N = 100, 20 | build_p N N N L, 21 | ground X, 22 | L => std.time (p X 0) T, 23 | print T. -------------------------------------------------------------------------------- /tests/sources/dt_multivar_long_list.elpi: -------------------------------------------------------------------------------- 1 | kind n type. 2 | type z n. 3 | type succ n. 4 | 5 | :index (10) 6 | pred p o:list n. 7 | p [z,z,z,z,z,z,z,z,z,z,z,z,z,z,z]. 8 | 9 | pred make_n i:int, o:n. 10 | make_n 0 z. 11 | make_n N (succ X) :- N > 0, N1 is N - 1, make_n N1 X. 12 | 13 | pred make_list i:int, i:n, i:n, o:list n. 14 | make_list 0 _ LastN [LastN] :- !. 15 | make_list ListLen N LastN [N | TL] :- 16 | ListLen > 0, ListLen' is ListLen - 1, 17 | make_list ListLen' N LastN TL. 18 | 19 | main :- 20 | make_n 5 N, 21 | make_n 2 Last, 22 | make_list 10 N Last L, 23 | print L. -------------------------------------------------------------------------------- /tests/sources/dt_off.elpi: -------------------------------------------------------------------------------- 1 | :index (1) % DT is off 2 | pred f i:list int. 3 | 4 | pred mk-index i:int, i:(pred i:list int), o:list prop. 5 | mk-index 0 _ []. 6 | mk-index N P [C|CL] :- N > 0, N1 is N - 1, mk-clause P 10 [N] C, mk-index N1 P CL. 7 | 8 | pred mk-clause i:(pred i:list int), i:int, i:list int, o:prop. 9 | mk-clause P 0 X (P X). 10 | mk-clause P N ACC C :- N > 0, N1 is N - 1, 11 | mk-clause P N1 [N|ACC] C. 12 | 13 | pred repeat i:int, i:prop. 14 | repeat 0 _. 15 | repeat N P :- N > 0, N1 is N - 1, P, !, repeat N1 P. 16 | 17 | main :- 18 | mk-index 100 f CL1, 19 | !, 20 | CL1 => std.do! [ 21 | std.time (repeat 300000 (f [1,2,3,4,5,6,7,8,9,10,1])) TFast, 22 | std.time (repeat 300000 (f [1,2,3,4,5,6,7,8,9,10,100])) TSlow, 23 | print "DT=" TFast, 24 | print "PT=" TSlow, 25 | ]. 26 | -------------------------------------------------------------------------------- /tests/sources/dt_order.elpi: -------------------------------------------------------------------------------- 1 | :index(1 1 _) 2 | pred f i:bool, i:string, o:int. 3 | 4 | :name "a" 5 | f tt X _ :- halt "what is" X. 6 | 7 | :before "a" 8 | f tt "1" 1. 9 | 10 | main :- 11 | f tt "1" N. -------------------------------------------------------------------------------- /tests/sources/dt_var.elpi: -------------------------------------------------------------------------------- 1 | :index(20) 2 | pred f i:int. 3 | f uvar :- print "uvar". 4 | f X :- var X, print "X". 5 | f 1 :- halt "bug". 6 | 7 | pred p i:list int. 8 | p [1,2,3] :- halt "bug p". 9 | p [1 | X] :- print "OK". 10 | 11 | pred exec i:prop. 12 | exec P :- (P, fail); true. 13 | 14 | main :- 15 | exec (f X), 16 | exec (p [1 | Y]). -------------------------------------------------------------------------------- /tests/sources/dt_var2.elpi: -------------------------------------------------------------------------------- 1 | :index(20) 2 | pred f o:int. 3 | f uvar :- print "uvar". 4 | f X :- var X, print "X". 5 | f 1 :- print "Y". 6 | 7 | main :- 8 | (f X, fail) ; true. -------------------------------------------------------------------------------- /tests/sources/dt_var3.elpi: -------------------------------------------------------------------------------- 1 | :index(20) 2 | pred f i:int. 3 | f uvar :- print "uvar". 4 | f X :- var X, print "X". 5 | f 1 :- print "Y". 6 | 7 | main :- f 1. -------------------------------------------------------------------------------- /tests/sources/elpi_only_llam.elpi: -------------------------------------------------------------------------------- 1 | :untyped main :- p (F X) F X => p (f x) f x. 2 | -------------------------------------------------------------------------------- /tests/sources/end_comment.elpi: -------------------------------------------------------------------------------- 1 | main. 2 | % foo -------------------------------------------------------------------------------- /tests/sources/eta.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | type c (tm -> A) -> tm. 3 | macro @ctx A :- c (_\ A). % to have depth > 0 in unif 4 | 5 | % to test the indexing 6 | pred k1 o:tm -> tm. 7 | k1 (x\ g x). 8 | pred k2 o:tm -> tm. 9 | k2 g. 10 | 11 | %mode (foo i i). 12 | pred foo i:(X -> X), i:(X -> X -> X). 13 | foo X (x1 \ (x2 \ X x2)) :- (print X). 14 | %% Fails, but should output `y` 15 | 16 | main :- 17 | pi f y\ 18 | % 4 branches in unif 19 | @ctx (x\ f x) = @ctx f, 20 | @ctx f = @ctx (x\ f x), 21 | @ctx (x\ f y x) = @ctx (f y), 22 | @ctx (f y) = @ctx (x\ f y x), 23 | 24 | % put some uvar around 25 | @ctx (f (X y)) = @ctx (x\ f y x), print X, 26 | @ctx (x\ f y x) = @ctx (f (Y y)), print Y, 27 | 28 | % index + adepth=2 <> bdepth=0 29 | k1 g, 30 | k2 (x\ g x), 31 | 32 | % regression #135 33 | foo y (x1 \ (x2 \ y x2)) 34 | . 35 | -------------------------------------------------------------------------------- /tests/sources/eta_oc.elpi: -------------------------------------------------------------------------------- 1 | type test-unif o -> o. 2 | test-unif T :- print "Original goal is" T, fail. 3 | test-unif T :- T, !, print "--> Unif success" T "\n". 4 | % test-unif T :- print "--> FAIL in this unification:" T "\n". 5 | 6 | pred p o:A. 7 | type f A -> B. 8 | type a A. 9 | 10 | main :- 11 | test-unif ((x\y\X x y) = (x\y\X y x)), !, 12 | test-unif (Q = (x\y\Q x y)), !, 13 | test-unif (Z = (x\y\Z y x)), !, 14 | (pi a\ test-unif (W a = (x\y\W a y x))), !, 15 | (pi b a\ test-unif (A a = (x\y\A a y x))), !, 16 | not (pi b a\ test-unif (B a = (x\y\f (B a x y)))), !, 17 | (pi b a\ test-unif (C a = (y\x\C y y x))), !, 18 | (p (x\f (a\a) x) => pi w\ p (f (x\x))), !, 19 | (p (f (x\x)) => pi w\ p (x\f (a\a) x)), !, 20 | (p (r\x\f (a\a) r x) => pi w\ p (r\f (x\x) r)), !, 21 | (p (r\f (x\x) r) => pi w\ p (r\x\f (a\a) r x)), !, 22 | test-unif ((r\D) = (x\y\r\D y x)), !, 23 | test-unif ((r\x\y\E x y) = (r\x\y\E x r)), !, 24 | (p (x\ F x a) => pi w r\ p (F r)), !, 25 | true. -------------------------------------------------------------------------------- /tests/sources/even-odd.elpi: -------------------------------------------------------------------------------- 1 | kind nat type. 2 | type zero nat. 3 | type succ nat -> nat. 4 | 5 | pred odd i:nat. 6 | pred even i:nat. 7 | pred double i:nat, o:nat. 8 | 9 | even zero. 10 | odd (succ X) :- even X. 11 | even (succ X) :- odd X. 12 | even X :- var X, declare_constraint (even X) [X]. 13 | odd X :- var X, declare_constraint (odd X) [X]. 14 | 15 | double zero zero. 16 | double (succ X) (succ (succ Y)) :- double X Y. 17 | double X Y :- var X, declare_constraint (double X Y) [X]. 18 | 19 | main :- odd X, not(X = zero), not(double Z X). 20 | 21 | constraint even odd double { 22 | rule (even X) (odd X) <=> fail. 23 | rule (double _ Y) <=> (even Y). 24 | } 25 | -------------------------------------------------------------------------------- /tests/sources/findall.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int, o:int. 2 | % pred q o:int, o:int. 3 | p 1 1. 4 | p 1 2. 5 | p 2 2. 6 | 7 | type test1, test2, test3, test4, test5 prop. 8 | 9 | test1 :- std.findall (p _A _B) [p 1 1, p 1 2, p 2 2]. 10 | test2 :- std.findall (p _ _) [p X 1, p 1 2, p 2 2], not(var X). 11 | test3 :- 12 | pi q : int -> int -> prop \ 13 | q 1 1 => 14 | q 1 2 => 15 | q 2 2 => 16 | (std.findall (q _ _) [q X 2, q 1 2, q 1 1], not (var X)). 17 | 18 | 19 | test4 :- 20 | pi q\ 21 | q 1 A => 22 | q 2 A => 23 | (std.findall (q _ _) [q 2 X, q 1 Y], (same_var X Y)). 24 | % this is super tricky but hard to implement differently. 25 | % q _ _ -> q A^1 B^1 26 | % q A^1 B^1 == q 1 X0 --restrict--> X0 := X1, A1 := _\X1 27 | % when we backtrack the "restriction" on X0 is lost 28 | 29 | test5 :- 30 | pi q\ 31 | q 1 A => 32 | q 2 A => 33 | (dprint A, std.spy (std.findall (q _ _Z) [q 2 X, q 1 Y]), same_var X Y). 34 | % this works because there is no restriction 35 | 36 | main :- test1, print 1, 37 | test2, print 2, 38 | test3, print 3, 39 | test4, print 4, 40 | test5, print 5. -------------------------------------------------------------------------------- /tests/sources/findall_csts.elpi: -------------------------------------------------------------------------------- 1 | main :- declare_constraint (U = 2) [U], 2 | findall_solutions (U = 1) Solns. -------------------------------------------------------------------------------- /tests/sources/fragment_exit.elpi: -------------------------------------------------------------------------------- 1 | pred r o:int -> int. 2 | q Y :- pi d\ r Y. 3 | r _. 4 | main :- pi c\ q (x\ X c x). 5 | -------------------------------------------------------------------------------- /tests/sources/fragment_exit2.elpi: -------------------------------------------------------------------------------- 1 | pred d. 2 | pred c. 3 | pred ignore i:prop. 4 | ignore _. 5 | main :- pi c\ Y c = (x\ X c x), ignore (Y c d). 6 | -------------------------------------------------------------------------------- /tests/sources/fragment_exit3.elpi: -------------------------------------------------------------------------------- 1 | pred ignore i:prop. 2 | pred f i:prop. 3 | ignore _. 4 | main :- (pi c\ sigma Y\ X c = Y), ignore (X (f d)). 5 | -------------------------------------------------------------------------------- /tests/sources/functionality/.gitignore: -------------------------------------------------------------------------------- 1 | .aux 2 | *.c* 3 | *.d 4 | *.mh 5 | *.o -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads01.elpi: -------------------------------------------------------------------------------- 1 | :functional pred q. 2 | 3 | :functional pred p i:(:functional pred). 4 | 5 | % THIS IS OK: 6 | % functionality relation of q is (Functional []) 7 | % functionality of first arg of p is (Functional []) 8 | % Functional [] ⊆ Functional [] 9 | p q. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads02.elpi: -------------------------------------------------------------------------------- 1 | pred q. 2 | 3 | :functional pred p i:(:functional pred). 4 | 5 | % THIS FAILS: 6 | % functionality relation of q is (Relational []) 7 | % functionality of first arg of p is (Functional []) 8 | % Relational [] ⊈ Functional [] 9 | p q. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads03.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:(:functional pred i:(pred)). 2 | :functional pred r i:(:functional pred). 3 | 4 | % THIS IS OK: 5 | % functionality relation of p is (Functional [Functional [Relational []]]) 6 | % functionality of r is (Functional [Functional []]) 7 | % (p r) is GOOD since first arg of p is `Functional [Relational []]` 8 | % and Functional [Functional []] ⊆ Functional [Relational []] 9 | % r (p r) is GOOD is first arg of r is `Functional []` and 10 | % Functional [Functional [Relational []] ⊆ Functional [] 11 | r (p r). 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads04.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:(:functional pred i:(:functional pred)). 2 | :functional pred r i:(pred). 3 | 4 | % THIS FAILS: 5 | % functionality relation of p is (Functional [Functional [Relational []]]) 6 | % functionality of r is (Functional [Functional []]) 7 | % (p r) is WRONG since first arg of p is `Functional [Functional []]` 8 | % and Functional [Relational []] ⊈ Functional [Functional []] 9 | r (p r). 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads05.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:(pred i:(pred)) i:(:functional pred i:(pred)) . 2 | 3 | % THIS FAILS: first A is relational. The second A is functional. 4 | % However relational ⊈ functional 5 | p A A. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads06.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:(:functional pred i:(pred)) i:(pred i:(pred)). 2 | 3 | % THIS IS OK: first A is functional. The second A is relation. 4 | % functional ⊆ relational 5 | p A A. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads07.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:(int -> (:functional pred) -> prop). 2 | 3 | pred q i:int, o:(:functional pred). 4 | 5 | % THIS IS OK: 6 | % functionality relation of q is 7 | % (Relational [NoProp, Functional[]]) ⊆ (Relational [NoProp, Functional[]]) 8 | p q. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads08.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:((:functional pred) -> prop). 2 | 3 | pred q o:(pred). 4 | 5 | % functionality relation of q is 6 | % (Relational [Relational]) ⊈ (Relational [Functional]) 7 | p q. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/heads/heads09_TODO.elpi: -------------------------------------------------------------------------------- 1 | :functional pred p i:((:functional pred) -> (:functional pred)). 2 | 3 | :functional pred q i:(:functional pred). 4 | 5 | p (x\q x). 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/meals.elpi: -------------------------------------------------------------------------------- 1 | func map (func A -> B), list A -> list B. 2 | 3 | map _ [] []. 4 | map F [X|Xs] [Y|Ys] :- F X Y, map F Xs Ys. 5 | 6 | kind guest type. 7 | kind dish type. 8 | 9 | pred likes i:guest, o:dish. 10 | 11 | func likes! guest -> dish. 12 | likes! G D :- likes G D, !. 13 | 14 | func meal list guest -> list dish. 15 | meal Gs M :- map likes! Gs M. 16 | meal Gs M :- map likes Gs M, !. 17 | % meal Gs M :- map likes Gs M. 18 | 19 | func once (pred i:A, o:B), A -> B. 20 | once P A B :- P A B, !. 21 | 22 | meal Gs M :- map (once likes) Gs M. 23 | 24 | func commit (pred i:A, o:B) -> (func A -> B). 25 | commit P (once P). 26 | 27 | func id (func A -> B) -> (func A -> B). 28 | id F F. 29 | 30 | meal Gs M :- commit likes F, map F Gs M. % ok 31 | % meal Gs M :- id likes F, map F Gs M. % nope 32 | 33 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test1.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | p 1 3. 6 | p 2 3. 7 | 8 | % The following rule hinders functionality, since `p 2 X` has two solutions for X 9 | p 2 4. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test1.m: -------------------------------------------------------------------------------- 1 | :- module test1. 2 | 3 | :- interface. 4 | :- import_module io. 5 | :- pred main(io::di, io::uo) is det. 6 | 7 | :- implementation. 8 | :- import_module int. 9 | 10 | % To compile it: mkdir -p .aux && mmc test1.m -o .aux/test 11 | p(1,2). 12 | p(2,X) :- X = 3; X = 4. 13 | 14 | :- import_module list. 15 | :- pred fold(pred(T, Acc, Acc), list(T), Acc, Acc). 16 | :- mode fold(in(pred(in, in, out) is det), in, in, out) is det. 17 | 18 | fold(_,[],A,A). 19 | fold(F,[X|XS],A,B) :- F(X,A,A1),fold(F,XS,A1,B). 20 | 21 | succ(X,Y) :- Y = X + 1. 22 | 23 | :- pred p(int::in, int::out) is nondet. 24 | :- pred succ(int::in,int::out) is det. 25 | :- pred giverel(pred(int)). 26 | :- mode giverel(out(pred(out) is nondet)) is multi. 27 | giverel(p(1)). 28 | giverel(p(1)). 29 | giverel(succ(1)). 30 | 31 | 32 | 33 | main(!IO). -------------------------------------------------------------------------------- /tests/sources/functionality/test10.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | 10 | p 4 X :- pi x\ sigma Y\ q x Y => q x Y => q 1 X. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test100.elpi: -------------------------------------------------------------------------------- 1 | % .YES 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | p 2 X :- pi x\ q x 2 => q 1 X. 9 | 10 | /* two new local clauses q x 2 and q y 3 are not overlapping, p is functional! */ 11 | p 3 X :- pi x\ q x 2 => pi y\ q y 3 => q 1 X. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test101.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f int -> int. 4 | func chain1 -> int. 5 | chain1 X :- 6 | pi x\ (f (A x) 3 :- !) => f _ X. 7 | func chain2 -> int. 8 | chain2 X :- 9 | pi x\ (f (Z x) 2 :- !) => chain1 X. 10 | main :- std.findall (chain2 X) L, print L. 11 | -------------------------------------------------------------------------------- /tests/sources/functionality/test102.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f int -> int. 4 | func chain1 -> int. 5 | chain1 X :- 6 | % Can't load this clause: no input with rigid-position local variable 7 | pi x\ f (A x) 3 => f _ X. 8 | func chain2 -> int. 9 | chain2 X :- 10 | pi x\ f (Z x) 2 => chain1 X. 11 | main :- std.findall (chain2 X) L, print L. 12 | -------------------------------------------------------------------------------- /tests/sources/functionality/test103.elpi: -------------------------------------------------------------------------------- 1 | pred p. 2 | func p. 3 | func g. 4 | g :- p. -------------------------------------------------------------------------------- /tests/sources/functionality/test104.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | 5 | func std.do (list (func)). 6 | 7 | % the input of g is pattern-matched. 8 | % we assume (g (f :- L)) is det. Then, 9 | % we assume (f :- L) is func. Then 10 | % we assume L is func 11 | func g (func) -> (func). 12 | g (g (f :- L) _) (f :- L) :- std.do L. 13 | 14 | 15 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test105.elpi: -------------------------------------------------------------------------------- 1 | func eq-db A, B, C. 2 | 3 | :index (1) 4 | func quantify-eq-db-idx prop -> prop. 5 | quantify-eq-db-idx (eq-db _ _ _ :- L) (pi x y\ eq-db _ _ _ :- L). 6 | 7 | 8 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test106.elpi: -------------------------------------------------------------------------------- 1 | func do (list (func)) ->. 2 | do []. 3 | do [P|PS] :- P, do PS. 4 | 5 | pred rel. 6 | 7 | func f -> (pred). 8 | f (do L) :- L = [rel]. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test107.elpi: -------------------------------------------------------------------------------- 1 | kind k1 type. 2 | kind k2 type -> type. 3 | 4 | type t11 list (func) -> k1. 5 | type t21 list A -> k2 A. 6 | 7 | kind k3 type. 8 | type t31 k2 (func) -> k3. 9 | type t32 k1 -> k3. 10 | 11 | pred rel. 12 | 13 | func g -> k3. 14 | g (t31 (t21 [rel])). % NO: k2 rel <> k2 func 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test108.elpi: -------------------------------------------------------------------------------- 1 | kind k1 type. 2 | kind k2 type -> type. 3 | 4 | type t11 list (func) -> k1. 5 | type t21 list A -> k2 A. 6 | 7 | kind k3 type. 8 | type t31 k2 (func) -> k3. 9 | type t32 k1 -> k3. 10 | 11 | pred rel. 12 | 13 | func g -> k3. 14 | g (t32 (t11 [rel])). % NO: passo a t11 una rel invece di un func 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test109.elpi: -------------------------------------------------------------------------------- 1 | func f int ->. 2 | 3 | func f1. 4 | 5 | f1 :- 6 | pi x\ (f x :- print "CIAO") => 7 | (f x, fail). 8 | 9 | f X :- halt "Mh". 10 | 11 | main :- f1. -------------------------------------------------------------------------------- /tests/sources/functionality/test11.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | % here we have variables in input position, overlap detection, 6 | % makes the predicate not functional... 7 | % NOTE: the query p 1 Y has two solutions for Y 8 | p 1 2. 9 | p X 3. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test110.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | % A simplified version from XXX, where the output of a predicate is a data. 4 | % This data should assume its arguments to have the determinacy declared in 5 | % the signature of the constructor being taken into account 6 | 7 | kind derive type. 8 | type derive string -> (func -> list (pred)) -> prop -> derive. 9 | 10 | pred derivation o:derive. 11 | 12 | func unfold-constants. 13 | unfold-constants :- 14 | derivation (derive _ Do _), !, 15 | Do [true]. 16 | 17 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test111.elpi: -------------------------------------------------------------------------------- 1 | func foo int ->. 2 | pred bad. 3 | 4 | 5 | main :- pi x\ (bad :- (foo x) => foo x, bad) => true. -------------------------------------------------------------------------------- /tests/sources/functionality/test112.elpi: -------------------------------------------------------------------------------- 1 | func foo int ->. 2 | pred bad. 3 | 4 | 5 | main :- pi x\ (bad :- pi x\ (foo x) => foo x, bad) => true. -------------------------------------------------------------------------------- /tests/sources/functionality/test113.elpi: -------------------------------------------------------------------------------- 1 | func f int ->. 2 | 3 | 4 | main :- 5 | pi x\ f x => true. 6 | 7 | f (X as (Y as Z)). -------------------------------------------------------------------------------- /tests/sources/functionality/test114.elpi: -------------------------------------------------------------------------------- 1 | func f int ->. 2 | 3 | 4 | main :- 5 | pi x\ f x => true. 6 | 7 | f (X as (Y as 3)). -------------------------------------------------------------------------------- /tests/sources/functionality/test115.elpi: -------------------------------------------------------------------------------- 1 | func f. 2 | pred r. 3 | 4 | f :- 5 | if true (if true r !) f. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test116.elpi: -------------------------------------------------------------------------------- 1 | func f. 2 | pred r. 3 | 4 | f :- 5 | if true (if true (r, !) !) f. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test117.elpi: -------------------------------------------------------------------------------- 1 | func f. 2 | pred r. 3 | 4 | f :- 5 | if true (if true (r, f) f) f. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test118.elpi: -------------------------------------------------------------------------------- 1 | func f. 2 | pred r. 3 | 4 | func f1 (func). 5 | 6 | f :- 7 | if true (if true (f1 r, f) f) f. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test12.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | /* this slightly differs from test11.elpi since 6 | * we explicitly put the uvar keyword in place of a unification variable 7 | * the input mode will therefore prevent the query `p 1 Y` to unify with 8 | * `p uvar 3. 9 | */ 10 | p 1 2. 11 | p uvar 3. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test13.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | /* another version of test11.elpi and test12.elpi 6 | * here the query `p 1 X` has clearly one distinct solution, 7 | * but `p X Y` has two. Therefore, p is not guaranteed to be functional 8 | */ 9 | p 1 2. 10 | p (uvar as X_) 3. 11 | p (uvar as Y_) 4. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test14.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred f i:int, o:int. 4 | 5 | pred q o:int. 6 | 7 | :functional 8 | pred r i:int, o:int. 9 | 10 | q 1. 11 | q 2. 12 | 13 | r X X. 14 | 15 | % Recall: q is not functional! 16 | % Note: in warren, the following rule is considered functional 17 | % since the input X should be ground, and therefore, q X does not 18 | % create any choice point for `r X Y` where Y can be assinged to 2 distinct 19 | % values. 20 | % In the implementation using the input mode of elpi this is no more true. 21 | f X Y :- q X, r X Y. 22 | 23 | main :- std.findall (f _ _) L, print L. 24 | -------------------------------------------------------------------------------- /tests/sources/functionality/test15.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | :functional 3 | pred f i:int, o:int. 4 | 5 | pred q o:int. 6 | 7 | :functional 8 | pred r i:int, o:int. 9 | 10 | q 1. 11 | q 2. 12 | 13 | r X X. 14 | 15 | % Recall: q is not functional! 16 | % This is similar to test14, but in this case, 17 | % the output of q is Y (which can have several distinct assignments). 18 | % However Y is functionally determined by then 1 Y :- q Y, r 1 Y. 19 | 20 | % Here the bang ensures that `Y` is functionally determined by the call to q 21 | f 2 Y :- q Y, !. 22 | 23 | main. 24 | -------------------------------------------------------------------------------- /tests/sources/functionality/test16.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | pred f o:int, o:int, o:int. 6 | 7 | % the variables of f are not used in the output, therefore, p remains functional 8 | p 4 Y :- f Z X W, Y = 4. 9 | 10 | % case similar to the previous one, where the output is not instantiated 11 | % all the variables in the body are never returned 12 | p 5 Y :- f Z X W, f X Z T. 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test16.m: -------------------------------------------------------------------------------- 1 | :- module test16. 2 | 3 | :- interface. 4 | 5 | :- import_module io. 6 | :- pred main(io::di, io::uo) is det. 7 | 8 | :- implementation. 9 | 10 | :- pred p(int::in, int::out) is semidet. 11 | :- pred f(int::out, int::out, int::out) is multi. 12 | 13 | f(1,2,3). 14 | f(2,3,1). 15 | f(1,3,2). 16 | 17 | p(4, Y) :- f(_Z,_X,_W), Y = 4. 18 | 19 | % ERROR: this makes the predicate non-det: 20 | % we may need to do backtracking in the body of p 21 | p(5, 3) :- f(Z,X,T), f(X,Z,T). 22 | 23 | main(!IO) :- 24 | io.write_line(10,!IO). 25 | 26 | % clear && mmc ../tests/sources/functionality/test1.m -------------------------------------------------------------------------------- /tests/sources/functionality/test17.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | pred q o:int. 3 | 4 | :functional 5 | pred do i:(func). 6 | do X :- X. 7 | 8 | :functional 9 | pred p i:int, o:int. 10 | 11 | :functional 12 | pred x i:int, o:int. 13 | % x 1 Y :- do (q X), Y = 3. % -> `do (q X)` is not functional, but X is not used in the output 14 | % x 2 Z :- p 3 Y, do (q Y), Z = 3. % -> Y is not functional determined, but not used in the output 15 | x 3 Y :- do (q Y), !. % -> `do (q X)` is not functional, but there is a bang after 16 | x 4 Y :- do (do (p 1 X)). % -> nested functional calls 17 | 18 | main. 19 | -------------------------------------------------------------------------------- /tests/sources/functionality/test18.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | pred q o:int. 3 | 4 | :functional 5 | pred do i:(func). 6 | % do X :- X. 7 | 8 | :functional 9 | pred x o:int. 10 | 11 | % this rule is not functional since `do` 12 | % is functional if its first argument is functional 13 | % however, q is not functional 14 | x Y :- do (q Y). 15 | 16 | main. 17 | -------------------------------------------------------------------------------- /tests/sources/functionality/test18.m: -------------------------------------------------------------------------------- 1 | :- module test18. 2 | 3 | :- interface. 4 | 5 | :- import_module io. 6 | :- pred main(io::di, io::uo) is det. 7 | 8 | :- implementation. 9 | 10 | :- pred q(int::out) is multi. 11 | q(0). 12 | q(1). 13 | 14 | :- pred do(pred). 15 | :- mode do(in((pred) is det)) is det. 16 | 17 | do(P) :- P. 18 | 19 | :- pred x(int::out) is det. 20 | 21 | x(Y) :- do(q(Y)). 22 | 23 | main(!IO) :- 24 | io.write_line(10,!IO). 25 | 26 | % cd out && clear && mmc ../tests/sources/functionality/test18.m 27 | 28 | -------------------------------------------------------------------------------- /tests/sources/functionality/test19.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | pred q o:int. 3 | 4 | :functional 5 | pred do i:(func). 6 | do X :- X. 7 | 8 | :functional 9 | pred x o:int. 10 | 11 | % similar to test18 but with nested 12 | % non functional call 13 | x Y :- do (do (q Y)). 14 | 15 | main. 16 | -------------------------------------------------------------------------------- /tests/sources/functionality/test2.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred s o:int. 7 | 8 | pred r i:int, o:int. 9 | pred q o:int. 10 | 11 | % THIS IS OK since a bang preclude distinct outputs 12 | p 1 3. 13 | p 2 3 :- !. 14 | /* functional context: everything before the cut is irrelevant for functionality */ 15 | /* moreover, we have parentheses around commas, i.e. a tree-like ast */ 16 | p 2 A :- (r 3 A, q A, std.map [] std.rev []), (!, true). 17 | p 2 X :- !, s X. /* X is a functionally determined by s */ 18 | p 2 5. 19 | 20 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test2.m: -------------------------------------------------------------------------------- 1 | :- module test2. 2 | 3 | :- interface. 4 | :- import_module io. 5 | :- pred main(io::di, io::uo) is det. 6 | 7 | :- implementation. 8 | :- import_module int. 9 | 10 | :- pred p(int::in, int::out) is semidet. 11 | p(1,2). 12 | p(2,X) :- if true then (X = 3) else false. 13 | 14 | 15 | main(!IO). -------------------------------------------------------------------------------- /tests/sources/functionality/test20.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | pred q o:int. 3 | :functional 4 | pred q' o:int. 5 | 6 | :functional 7 | pred do' i:prop, i:(func). 8 | do' X Y :- X, !, Y. 9 | 10 | :functional 11 | pred x o:int. 12 | 13 | % similar to test19, with non-functional argument 14 | x Z :- do' (q Z) (q' Z). 15 | 16 | main. 17 | -------------------------------------------------------------------------------- /tests/sources/functionality/test21.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred wrong-if i:prop, i:(func), i:(func). 4 | 5 | % The problem is the call to P: P is relational 6 | % and having it in the body could make wrong-if behave as a relation 7 | wrong-if P Q _ :- !, P, Q, print "123". 8 | wrong-if _ _ R :- R. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test22.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | :functional pred f o:int. 3 | :functional pred r o:(func -> int). 4 | 5 | f R :- r X, X R. 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test22.m: -------------------------------------------------------------------------------- 1 | :- module test22. 2 | 3 | :- interface. 4 | 5 | :- import_module io. 6 | 7 | :- pred main(io::di, io::uo) is det. 8 | 9 | :- implementation. 10 | 11 | :- import_module list. 12 | :- import_module int. 13 | 14 | :- pred f(int::out) is det. 15 | :- pred r(pred int). 16 | 17 | :- mode r(out(pred(out) is det)) is det. 18 | 19 | :- pred aux(int::out) is det. 20 | 21 | aux(3). 22 | 23 | f(X) :- r(P), P(X). 24 | 25 | r(aux). 26 | 27 | main(!IO) :- 28 | f(S), 29 | io.write_line(S,!IO). -------------------------------------------------------------------------------- /tests/sources/functionality/test23.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred f i:int, o:int. 4 | 5 | pred q o:int. 6 | 7 | :functional 8 | pred r i:int, o:int. 9 | 10 | q 1. 11 | q 2. 12 | 13 | r X X. 14 | 15 | % similar to test14, but this time the non functional variable is the output Y 16 | f X Y :- q Y, r X Y. 17 | 18 | 19 | main :- std.findall (f _ _) R, print R. -------------------------------------------------------------------------------- /tests/sources/functionality/test24.elpi: -------------------------------------------------------------------------------- 1 | % OK 2 | :functional 3 | pred f o:int. 4 | 5 | :functional 6 | pred r o:(func -> int). 7 | 8 | :functional 9 | pred r' o:(pred o:int). 10 | 11 | f R :- r X, r' X, X R. % X is used 2 times with different functionalities: we 12 | % keep the minimum of them 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test24.m: -------------------------------------------------------------------------------- 1 | :- module test24. 2 | 3 | :- interface. 4 | 5 | :- import_module io. 6 | :- pred main(io::di, io::uo) is det. 7 | :- implementation. 8 | 9 | :- import_module int. 10 | 11 | :- pred f(int::out) is det. 12 | 13 | :- pred r(pred int). 14 | :- mode r(out(pred(out) is det)) is det. 15 | 16 | :- pred r1(pred int). 17 | :- mode r1(out(pred(out) is multi)) is det. 18 | 19 | :- pred aux(int::out) is det. 20 | :- pred aux1(int::out) is multi. 21 | 22 | f(X) :- r(P), P(X). 23 | 24 | aux(3). 25 | r(aux). 26 | 27 | aux1(3). 28 | aux1(4). 29 | 30 | r1(aux1). 31 | 32 | main(!IO) :- 33 | f(S), 34 | io.write_line(S,!IO). -------------------------------------------------------------------------------- /tests/sources/functionality/test25.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional pred f o:int. 3 | :functional pred r o:(pred o:int). 4 | 5 | % similar to test22, but the output of r is non-functional 6 | % therefore it cannot be called on variable used in the output of f 7 | f R :- r X, X R. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test26.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | kind tm type. 3 | 4 | type app tm -> tm -> tm. 5 | type lam (tm -> tm) -> tm. 6 | type const int -> tm. 7 | 8 | :functional 9 | pred p i:tm, o:tm. 10 | p (const A) (const A). 11 | 12 | % Overlap with as operator 13 | p (const _ as A) A. 14 | 15 | main. 16 | -------------------------------------------------------------------------------- /tests/sources/functionality/test27.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | kind tm type. 3 | 4 | type app tm -> tm -> tm. 5 | type lam (tm -> tm) -> tm. 6 | type const int -> tm. 7 | 8 | :functional 9 | pred p i:tm, o:tm. 10 | p (lam (x\ lam (y\ B x y))) (lam (x\ lam (y\ B x y))). 11 | % Overlap with HO terms: B x y overlaps with A x 12 | p (lam (x\ lam (A x))) (lam (x\ lam (A x))). 13 | 14 | main. 15 | -------------------------------------------------------------------------------- /tests/sources/functionality/test28.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | pred q o:int. 3 | q 1. 4 | q 2. 5 | 6 | 7 | :functional 8 | pred q' o:int. 9 | 10 | :functional 11 | pred do' i:prop, i:(func). 12 | do' X Y :- X, !, Y. 13 | 14 | :functional 15 | pred x o:int. 16 | 17 | % similar to test20. The non functional argument Y is returned 18 | % as the output of x. However, a non functional pred passed to a functional 19 | % predicate is either not called or appears in a functional context. 20 | % therefore, the output Y has at most one distinct value. 21 | x Y :- do' (q Y) (q' Z). 22 | 23 | main. 24 | -------------------------------------------------------------------------------- /tests/sources/functionality/test29.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | :functional pred r o:int, i:int. 3 | 4 | :functional pred p i:(pred i:int). 5 | 6 | :functional pred q o:int. 7 | q X :- p (r X). 8 | 9 | main. 10 | -------------------------------------------------------------------------------- /tests/sources/functionality/test29.m: -------------------------------------------------------------------------------- 1 | 2 | :- module test29. 3 | 4 | :- interface. 5 | 6 | :- import_module io. 7 | :- pred main(io::di, io::uo) is det. 8 | :- implementation. 9 | 10 | :- import_module int. 11 | 12 | :- pred r(int::out, int::out) is det. 13 | 14 | r(5,5). 15 | 16 | :- pred p(pred int). 17 | :- mode p(in(pred(out) is det)) is det. 18 | 19 | p(X) :- X(_). 20 | 21 | :- pred q(int::out) is det. 22 | 23 | q(X) :- p(r(X)). 24 | 25 | main(!_). 26 | -------------------------------------------------------------------------------- /tests/sources/functionality/test3.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred q o:int. 4 | 5 | pred t o:int. 6 | 7 | 8 | % TEST 3 9 | q X :- t X. % This breaks functionality, t is not functional 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test30.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % HERE WE HAVE A MODE ERROR 3 | pred r i:int, o:int. 4 | 5 | :functional pred p i:(func -> int). 6 | 7 | :functional pred q o:int. 8 | q X :- p (r X). 9 | 10 | main. 11 | -------------------------------------------------------------------------------- /tests/sources/functionality/test30.m: -------------------------------------------------------------------------------- 1 | 2 | :- module test30. 3 | 4 | :- interface. 5 | 6 | :- import_module io. 7 | :- pred main(io::di, io::uo) is det. 8 | :- implementation. 9 | 10 | :- import_module int. 11 | 12 | :- pred r(int::out, int::out) is det. 13 | 14 | r(5,5). 15 | r(4,5). 16 | 17 | :- pred p(pred int). 18 | :- mode p(in(pred(out) is det)) is det. 19 | 20 | p(X) :- X(_). 21 | 22 | :- pred q(int::out) is det. 23 | 24 | q(X) :- p(r(X)). 25 | 26 | main(!_). 27 | -------------------------------------------------------------------------------- /tests/sources/functionality/test31.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % Test on func of outputs 3 | pred twice i:prop. 4 | twice X :- X; X. 5 | 6 | pred give-fun o:(func). 7 | give-fun (twice X). 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test32.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | % Test on func of outputs 3 | pred twice i:prop. 4 | twice X :- X; X. 5 | 6 | func once prop ->. 7 | once X :- X, !. 8 | 9 | func do (func) ->. 10 | do X :- X. 11 | 12 | func map (func A -> B), list A -> list B. 13 | 14 | pred give-fun o:(func). 15 | give-fun (once (twice X)). 16 | give-fun true. 17 | give-fun (map (x\y\ once (twice y)) [] []). 18 | give-fun (map F [] []) :- F = (x\y\ once (twice y)). 19 | 20 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test33.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % Test on func of outputs 3 | pred twice i:prop. 4 | twice X :- X; X. 5 | 6 | func do (func) ->. 7 | do X :- X. 8 | 9 | pred give-fun o:(func). 10 | give-fun (do (twice X)). 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test34.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % Test on func of outputs 3 | pred twice i:prop. 4 | twice X :- X; X. 5 | 6 | func map (func A -> B), list A -> list B. 7 | 8 | pred give-fun o:(func). 9 | give-fun (map (x\y\ (twice y)) [] []). 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test35.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % Test on func of outputs 3 | 4 | func do (func) ->. 5 | 6 | pred give-fun o:(func). 7 | % There is no way to ensure that X, which is an input of do is 8 | % really deterministic, i.e. -> error 9 | give-fun (do X). 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test36.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | % Test on func of outputs 3 | func do (func) ->. 4 | 5 | pred give-fun o:(func). 6 | give-fun (do true). 7 | 8 | func f. 9 | f :- give-fun (do X), !, X. % Note that X is an input of do, therefore, assumed 10 | % to have the determinacy in the signature of do 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test37.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % Test on func of outputs 3 | func do (func) ->. 4 | 5 | pred give-fun o:(func). 6 | give-fun (give-fun X). 7 | 8 | func f. 9 | f :- give-fun (give-fun X), !, X. % Note that X is an output of the second give-fun call. 10 | % This means that X is considered relational 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test38.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % returns the divisors of an int one by one 3 | pred divisors i:int, o:int. 4 | 5 | pred p o:(func). 6 | % the output is not functional 7 | p (pi x\ divisors x Y). 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test39.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | func succ int -> int. 3 | 4 | pred p o:(func). 5 | p (pi x\ succ x Y). 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test3_1.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred q o:int. 4 | 5 | pred t o:int. 6 | 7 | 8 | % TEST 3 9 | q Y :- Y = {t}. % This breaks functionality, t is not functional 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test4.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | /* the local premise may break functionality */ 10 | p 1 X :- (pi x\ q 2 x :- x = 4) => q 1 X. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test40.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | func succ int -> int. 3 | 4 | pred p o:(func). 5 | p (pi x\ succ x Y :- true). 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test41.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | func succ int -> int. 3 | 4 | pred p o:(func). 5 | % the output is not functional: the body of succ is rel 6 | p (pi x\ succ x Y :- p _). 7 | 8 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test42.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | func succ int -> int. 3 | 4 | pred p o:(func). 5 | p X :- 6 | % OK, we can return a discard as output of a clause 7 | p _ => X = true. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test43.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | func succ int -> int. 3 | 4 | pred p i:(pred), o:(func). 5 | p X X :- 6 | % X should not be set functional in the body of the following clause: 7 | % we can't know if the clause will be called in the body 8 | (p _ X :- X = true) => true. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test44.elpi: -------------------------------------------------------------------------------- 1 | % OK 2 | func succ int -> int. 3 | 4 | pred p i:(pred), o:(func). 5 | p X X :- 6 | (p _ X :- X = true) => X = true. 7 | 8 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test45.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func map (func A -> B), list A -> list B. 4 | map _ [] []. 5 | map F [X|Xs] [Y|Ys] :- F X Y, map F Xs Ys. 6 | 7 | func map! (pred i:A, o:B), list A -> list B. 8 | map! _ [] []. 9 | % This is a good example of failure :-), 10 | % The det checker, should be map! F Xs Ys 11 | map! F [X|Xs] [Y|Ys] :- F X Y, !, map F Xs Ys. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test46.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func map (func A -> B), list A -> list B. 4 | map _ [] []. 5 | map F [X|Xs] [Y|Ys] :- F X Y, map F Xs Ys. 6 | 7 | func map! (pred i:A, o:B), list A -> list B. 8 | map! _ [] []. 9 | map! F [X|Xs] [Y|Ys] :- F X Y, !, map! F Xs Ys. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test47.elpi: -------------------------------------------------------------------------------- 1 | func do (list (func)) ->. 2 | do []. 3 | do [X|Xs] :- X, do Xs. 4 | 5 | % Following clauses fails determinacy due to the absence of 6 | % input mode tracking 7 | % do X :- X = [A|As], A, do As. 8 | % do X :- Y = X, Y = [A|As], A, do As. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test48.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | % test for variadic predicates 3 | 4 | pred r. 5 | 6 | func p. 7 | p :- X = halt r, X. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test49.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | % test for spilling 3 | 4 | func p -> prop, fprop. 5 | 6 | func q. 7 | 8 | q :- X = {p R}, X. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test5.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | /* the local premise makes q not functional... */ 10 | p 1 X :- (pi x\ q 1 x :- x = 4) => q 1 X. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test5.m: -------------------------------------------------------------------------------- 1 | :- module test5. 2 | 3 | :- interface. 4 | :- import_module io. 5 | :- pred main(io::di, io::uo) is det. 6 | 7 | :- implementation. 8 | :- import_module int. 9 | 10 | :- pred p(int::in, int::out) is semidet. 11 | :- pred q(int::in, int::out) is semidet. 12 | 13 | q(1,1). 14 | p(1,R) :- (all [Y] (q(2, Y) <= Y = 3)) => q(2, R). 15 | 16 | main(!IO). -------------------------------------------------------------------------------- /tests/sources/functionality/test50.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | % test for spilling 3 | 4 | func p -> prop, fprop. 5 | 6 | func q. 7 | 8 | q :- X = {p R}, R. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test51.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | % test for spilling 3 | 4 | typeabbrev x (func -> prop, fprop). 5 | 6 | type p x. 7 | 8 | func r prop, fprop. 9 | 10 | func q. 11 | 12 | q :- r {p}. 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test52.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func map (func A -> B), list A -> list B. 4 | map _ [] []. 5 | map F [X|Xs] [Y|Ys] :- F X Y, map F Xs Ys. 6 | 7 | pred divisor_help i:int, i:int, o:int. 8 | divisor_help N N N :- !. 9 | divisor_help N M N :- 0 is M mod N. 10 | divisor_help N M R :- N < M, N1 is N + 1, divisor_help N1 M R. 11 | 12 | pred divisor i:int, o:int. 13 | divisor N M :- divisor_help 1 N M. 14 | 15 | func give-div list int -> (list(list int)). 16 | give-div L L1 :- 17 | X = (x\y\x y), % the dtype of X is inferred from the next line 18 | F = map X, 19 | F [map divisor L] L1. % HERE WE FAIL: the list applied to F is a list of relations instead of functions 20 | 21 | main :- std.findall (give-div [1,2] R) L, map (x\y\ x = give-div _ [y]) L L1, print L1. 22 | -------------------------------------------------------------------------------- /tests/sources/functionality/test53.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func map (func A -> B), list A -> list B. 4 | map _ [] []. 5 | map F [X|Xs] [Y|Ys] :- F X Y, map F Xs Ys. 6 | 7 | pred divisor_help i:int, i:int, o:int. 8 | divisor_help N N N :- !. 9 | divisor_help N M N :- 0 is M mod N. 10 | divisor_help N M R :- N < M, N1 is N + 1, divisor_help N1 M R. 11 | 12 | pred divisor i:int, o:int. 13 | divisor N M :- divisor_help 1 N M. 14 | 15 | func commit! (pred i:A, o:B), A -> B. 16 | commit! F A B :- F A B, !. 17 | 18 | func give-div list int -> (list(list int)). 19 | give-div L L1 :- 20 | X = (x\y\x y), % the dtype of X is inferred from the next line 21 | F = map X, 22 | F [map (commit! divisor) L] L1. 23 | 24 | main :- std.findall (give-div [1,2] R) L, map (x\y\ x = give-div _ [y]) L L1, print L1. 25 | -------------------------------------------------------------------------------- /tests/sources/functionality/test54.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | pred rel. 5 | 6 | f :- 7 | % Fails since y is assigned to a rel, rel is not fprop 8 | ((y\ y = rel) : (func -> fprop)) = F, 9 | F R, 10 | R. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test55.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | pred rel. 5 | 6 | f :- 7 | % Fails since we cannot load flex rules 8 | X = rel, X => true. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test56.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | func f1 fprop. 5 | 6 | pred rel. 7 | 8 | f :- 9 | X = ((x\ f1 x :- x) : (pred i:fprop)), 10 | X rel. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test57.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | func f1 fprop. 5 | 6 | typeabbrev tt fprop -> fprop. 7 | 8 | pred rel. 9 | 10 | f :- 11 | % Here the body of f1 is relational 12 | X = ((x\ f1 x :- x) : (func prop)), 13 | X rel. 14 | 15 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test58.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | func f1 fprop. 5 | 6 | typeabbrev tt fprop -> fprop. 7 | 8 | pred rel. 9 | 10 | f :- 11 | % in lambda x is in output position. It cannot be assumed functional 12 | % in the clause `f1 x :- x`. 13 | X = ((x\ f1 x :- x) : tt), 14 | X rel. 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test59.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | func f1 fprop. 5 | 6 | f :- 7 | X = ((x\ f1 x :- x) : (func fprop)), 8 | X f. 9 | 10 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test6.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | % Nested local clauses error... 10 | p 1 X :- pi z\ (pi x\ q z x :- x = 4) => (q 1 Z, (q 3 4) => q Z X). 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test60.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | func f1 fprop. 5 | 6 | typeabbrev t (func fprop). 7 | 8 | f :- 9 | X = ((x\ f1 x :- x) : t), 10 | X f. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test61.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | func f1 fprop. 5 | pred rel. 6 | 7 | typeabbrev t (func fprop). 8 | 9 | f :- 10 | X = ((x\ f1 x :- x) : t), 11 | % Good lambda in X, but wrongly called below 12 | X rel. 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test62.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | pred rel. 5 | 6 | f :- 7 | X = (x\ 3), 8 | % Good lambda in X, but wrongly called below 9 | Z = X _. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test63.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | func f1 -> fprop. 5 | 6 | f :- 7 | % PARTIAL APP 8 | X = (x\ f1), 9 | X R F, 10 | F. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test64.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f. 4 | func f1 -> fprop. 5 | 6 | f :- 7 | % PARTIAL APP 8 | F1 = f1, 9 | X = (x\ F1), 10 | X R F, 11 | F. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test65.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | func f1 -> fprop. 5 | 6 | f :- 7 | % F = f1, 8 | % PARTIAL APP 9 | X = (x\ F), % No guarantee F is functional... 10 | X 3, 11 | F. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test66.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func f -> fprop. 4 | func g -> fprop. 5 | pred rel. 6 | func f1. 7 | 8 | f1 :- 9 | (f (g rel) => f X), X. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test67.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f -> fprop. 4 | func g -> fprop. 5 | pred rel. 6 | func f1. 7 | 8 | f1 :- 9 | (f (g rel) => f X), X = g Y, Y. 10 | 11 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test68.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | % If we look for Warren's functionality, then the example above could 4 | % be accepted since there is no output, and more in general a 0-ary 5 | % predicate cannot unify anything. But not in our implementation. 6 | % A counter example, see test69.elpi 7 | pred p. 8 | p. 9 | p. 10 | func f. 11 | f :- p. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test69.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | % Note that in the example, below, due to the load of local clauses, 4 | % f is not a function. 5 | pred x. 6 | func f -> int. 7 | f Y :- (x :- Y = 3) => (x :- Y = 4) => x. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test7.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | /* the local premise makes q not functional... */ 10 | p 1 X :- (pi x\ q 2 x :- x = 4) => (q 1 Z, q 2 4 => q Z X). 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test70.elpi: -------------------------------------------------------------------------------- 1 | func p. 2 | p :- (p ; p), !, p, (p ; p). -------------------------------------------------------------------------------- /tests/sources/functionality/test71.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | % From paper 4 | func id (func A -> B) -> (func A -> B). 5 | func map (func A -> B), list A -> list B. 6 | func compose (func A -> B), (func B -> C), A -> C. 7 | compose F G X Y :- F X R, G R Y. 8 | typeabbrev (flist A B) (func list A -> list B). 9 | func fuse (flist A B), (flist B C) -> (flist A C). 10 | fuse (map A) (map B) (map C) :- id (compose A B) C. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test72.elpi: -------------------------------------------------------------------------------- 1 | % OK 2 | 3 | func succ int -> int. 4 | 5 | succ 3 4 :- true, !, false. 6 | 7 | succ X_ 5 :- pi x\ !. 8 | succ X_ 6 :- !. 9 | succ uvar _ :- !. 10 | succ _ _ :- pi x\ (true :- !) => !. 11 | 12 | succ 1 _. 13 | succ 2 _. 14 | succ uvar _. 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test73.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | kind t type. 4 | type k fprop -> t. 5 | 6 | pred q. 7 | 8 | func p -> t. 9 | % q is not fprop inside k 10 | p (k q). 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test74.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func f. 4 | pred rel. 5 | 6 | f :- 7 | % Cast error: y is not rel in the output of y 8 | ((y\ y = rel) : (func -> fprop)) = F, 9 | F R, 10 | R. 11 | 12 | func f -> fprop. 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test75.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | kind k type. 4 | type k0 (func -> fprop) -> k. 5 | 6 | func fst-proj k -> (func -> fprop). 7 | fst-proj (k0 F) F. 8 | 9 | pred g. 10 | 11 | func give-rel -> prop. 12 | give-rel g. 13 | 14 | func f. 15 | % Since k0 is constructed with a wrong argument (give-rel returns a prop and not a fprop) 16 | % the call to `fst-proj` is wrong 17 | f :- fst-proj (k0 give-rel) X, X Y, Y. 18 | 19 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test76.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | pred p i:prop, i:list prop, o:prop. 4 | p Head Body (Head :- Body). 5 | 6 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test77.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | pred q o:int. 3 | 4 | func f -> int. 5 | 6 | func p. 7 | p :- std.map [f,f] (x\y\x y) _. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test78.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | pred q o:int. 3 | 4 | func f -> int. 5 | 6 | func p. 7 | p :- std.map [f,q] (x\y\x y) _. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test79.elpi: -------------------------------------------------------------------------------- 1 | %YES 2 | 3 | func make-deterministic (pred i:A, o:B) -> (func A -> B). 4 | make-deterministic P (x\y\ P x y, !). 5 | 6 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test8.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | 10 | % This fails, since the local rule unifies with `r 1 1` 11 | p 5 Y :- sigma X Y\ q X Y => q 1 Y. 12 | 13 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test80.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | pred q. 4 | 5 | func p. 6 | 7 | p :- 8 | pi x\ 9 | X x = q, 10 | X x = p, % `X x` is a function since it is unified with p. Therefore `X : int -> func` 11 | X 3, % `X 3` is a function, the call is correct 12 | Y x = print, % `Y x` is a function 13 | Y x = true, % 14 | Z x = print, 15 | % Z 3 4 5, 16 | % TODO: add also this Z 3 4 5 as premise, this should pass 17 | pi y\ pi x\ 18 | y x = q, 19 | y x = print, 20 | y 3 21 | . 22 | 23 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test81.elpi: -------------------------------------------------------------------------------- 1 | 2 | func map (func int -> (func)). 3 | map F :- F 3 G, G. 4 | 5 | func good -> int, (func). 6 | good 3 true. 7 | 8 | func bad int, (func) -> . 9 | bad _ _. 10 | 11 | main :- 12 | std.filter [] (std.mem []) L1, 13 | map bad. 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/sources/functionality/test82.elpi: -------------------------------------------------------------------------------- 1 | 2 | func map (func int -> (func)). 3 | map F :- F 3 G, G. 4 | 5 | func good -> int, (func). 6 | good 3 true. 7 | 8 | func bad int, (func) -> . 9 | bad _ _. 10 | 11 | main :- 12 | std.filter [] (std.mem []) L1, 13 | map good. 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/sources/functionality/test83.elpi: -------------------------------------------------------------------------------- 1 | 2 | func succ int -> int. 3 | succ X X. 4 | 5 | func map (func (func int -> int)). 6 | map F :- F succ. 7 | 8 | func good (func int, int ->). 9 | good F :- F 3 3. 10 | 11 | func bad (func -> int, int). 12 | bad G :- G A B. 13 | 14 | main :- 15 | map bad. 16 | %map good. 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/sources/functionality/test84.elpi: -------------------------------------------------------------------------------- 1 | 2 | func succ int -> int. 3 | succ X X. 4 | 5 | func map (func (func int -> int)). 6 | map F :- F succ. 7 | 8 | func good (func int, int ->). 9 | good F :- F 3 3. 10 | 11 | func bad (func -> int, int). 12 | bad G :- G A B. 13 | 14 | main :- 15 | %map bad. 16 | map good. 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/sources/functionality/test85.elpi: -------------------------------------------------------------------------------- 1 | 2 | func succ int -> int. 3 | succ X X. 4 | 5 | func map (func (func int -> int)). 6 | map F :- F succ. 7 | 8 | func good (func int, int ->). 9 | good F :- F 3 3. 10 | 11 | func bad (func -> int, int). 12 | bad G :- G A B. 13 | 14 | main :- X = good, not(X = bad). 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/sources/functionality/test86.elpi: -------------------------------------------------------------------------------- 1 | 2 | func succ int -> int. 3 | succ X X. 4 | 5 | func map (func (func int -> int)). 6 | map F :- F succ. 7 | 8 | func good (func int, int ->). 9 | good F :- F 3 3. 10 | 11 | func bad (func -> int, int). 12 | bad G :- G A B. 13 | 14 | main :- X = bad, not(X = good). 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/sources/functionality/test87.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred p i:(func A, B, C -> D), i:C, o:D. 3 | p F X Y :- F _ _ X Y. 4 | 5 | main :- 6 | p (x\y\triple_1) (triple 1 2 3) _. 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/sources/functionality/test88.elpi: -------------------------------------------------------------------------------- 1 | 2 | 3 | main :- 4 | std.map [] (m\r\sigma D\ D = [], std.map D (d\r\r = pr d m) r) _. 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/sources/functionality/test89.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | % Local variable hiding: in the term below, r is defined twice with different types 4 | main :- 5 | std.map [] (m\r\sigma D\ D = [], std.map D (d\r\r = pr d m) r) ES2. -------------------------------------------------------------------------------- /tests/sources/functionality/test9.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | :functional 3 | pred p i:int, o:int. 4 | 5 | :functional 6 | pred q i:int, o:int. 7 | 8 | q 1 1. 9 | 10 | p 1 X :- pi x y\ q x x => q x y => q 1 X. 11 | 12 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test90.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func q (func). 4 | pred r. 5 | func f. 6 | 7 | f :- std.do! [q r]. 8 | 9 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test91.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | kind t type -> type. 4 | type k A -> fprop -> t A. 5 | 6 | func f1 fprop ->. 7 | 8 | func q (t fprop). 9 | q (k F1 F2) :- F1, !, F2. 10 | 11 | func f. 12 | pred q. 13 | 14 | f :- q (k (f1 q) f). 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test92.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | kind t type -> type. 4 | type k A -> fprop -> t A. 5 | 6 | func f1 fprop ->. 7 | 8 | func q (t prop). 9 | q (k F1 F2) :- F1, !, F2. 10 | 11 | func f. 12 | pred q. 13 | 14 | f :- q (k (f1 q) f). 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test93.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | kind t type -> type. 4 | type k A -> fprop -> t A. 5 | 6 | func f1 fprop ->. 7 | 8 | func q (t prop). 9 | q (k F1 F2) :- F1, !, F2. 10 | 11 | func f. 12 | pred q. 13 | 14 | f :- q (k (f1 f) f). 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test94.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | kind t type -> type. 4 | type k A -> fprop -> t A. 5 | 6 | func f1 fprop ->. 7 | 8 | func q (t prop). 9 | q (k F1 F2) :- F1, !, F2. 10 | 11 | func f. 12 | pred r. 13 | 14 | f :- q (k (f1 f) r). 15 | 16 | main. -------------------------------------------------------------------------------- /tests/sources/functionality/test95.elpi: -------------------------------------------------------------------------------- 1 | % YES 2 | 3 | func foo int, int. 4 | 5 | func g3. 6 | g3 :- 7 | pi x\ (pi X\ foo x X :- print "AA") => 8 | pi y\ (pi X\ foo X y :- print "BB", !) => 9 | std.findall (foo x y) [_]. 10 | 11 | 12 | main :- g3. -------------------------------------------------------------------------------- /tests/sources/functionality/test96.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func foo int, int. 4 | 5 | func g3. 6 | g3 :- 7 | % Overlapping error 8 | pi x\ (pi X\ foo x X :- print "AA") => 9 | pi y\ (pi X\ foo X y :- print "BB") => 10 | std.findall (foo x y) [_]. 11 | 12 | 13 | main :- g3. -------------------------------------------------------------------------------- /tests/sources/functionality/test97.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func foo int, int. 4 | 5 | func g3. 6 | g3 :- 7 | % Overlapping error 8 | sigma X\ 9 | pi x\ (pi X\ foo x X :- print "AA") => 10 | pi y\ (foo X y :- print "BB") => 11 | std.findall (foo x y) [_]. 12 | 13 | 14 | main :- g3. -------------------------------------------------------------------------------- /tests/sources/functionality/test98.elpi: -------------------------------------------------------------------------------- 1 | % NO 2 | 3 | func foo int, int. 4 | 5 | func g3. 6 | g3 :- 7 | pi a\ 8 | pi x\ (pi X\ foo x X :- print "AA") => 9 | pi y\ (foo a y :- print "BB") => 10 | std.findall (foo x y) [_]. 11 | 12 | 13 | main :- g3. -------------------------------------------------------------------------------- /tests/sources/functionality/test99.elpi: -------------------------------------------------------------------------------- 1 | pred p. 2 | 3 | func f. 4 | 5 | f :- std.once (p, p). 6 | 7 | main. -------------------------------------------------------------------------------- /tests/sources/general_case.elpi: -------------------------------------------------------------------------------- 1 | kind i type. 2 | type app (prop -> prop) -> prop -> prop. 3 | type ignore, foo A -> prop. 4 | type c prop. 5 | app F X :- F X. 6 | c. 7 | ignore _. 8 | foo P :- pi d\ ignore P. 9 | main :- app (x\x) c, F = (y \ y), F c, (pi d\ F c), 10 | foo (G c). 11 | -------------------------------------------------------------------------------- /tests/sources/general_case2.elpi: -------------------------------------------------------------------------------- 1 | pred c o:int. 2 | pred q o:int -> prop. 3 | p F :- F (x\ c x). 4 | q (x\ c x). 5 | main :- p (y\ pi z\ q y). 6 | -------------------------------------------------------------------------------- /tests/sources/general_case3.elpi: -------------------------------------------------------------------------------- 1 | pred f o:int, o:int. 2 | main :- 3 | (pi c\ sigma X\ pi d\ (X d = f c d, Y c = X)), 4 | Y = c\ d\ f c d. 5 | -------------------------------------------------------------------------------- /tests/sources/graft_before.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int, o:int. 2 | pred q o:int. 3 | 4 | p 0 0. 5 | 6 | :name "0" q 0. 7 | 8 | p 0 2. 9 | 10 | :before "0" p 0 1. 11 | 12 | main :- std.findall (p X Y) [p 0 0, p 0 1, p 0 2]. -------------------------------------------------------------------------------- /tests/sources/graft_before_same.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int, o:int. 2 | 3 | p 0 0. 4 | 5 | :name "0" p 0 10. 6 | 7 | p 0 2. 8 | 9 | :before "0" p 0 1. 10 | 11 | main :- std.findall (p X Y) [p 0 0, p 0 1, p 0 10, p 0 2]. -------------------------------------------------------------------------------- /tests/sources/graft_remove.elpi: -------------------------------------------------------------------------------- 1 | % Classic index 2 | :index (1) "Map" 3 | pred p o:int. 4 | 5 | :name "p0" p 0. 6 | 7 | :remove "p0" p _. 8 | 9 | % Dtree 10 | :index (1) "DTree" 11 | pred q o:int. 12 | 13 | :name "q0" q 0. 14 | 15 | :remove "q0" q _. 16 | 17 | % Hmap 18 | :index (1) "Hash" 19 | pred r o:int. 20 | 21 | :name "r0" r 0. 22 | 23 | :remove "r0" r _. 24 | 25 | 26 | main :- 27 | std.findall (p _) LP, std.assert! (LP = []) "wrong", 28 | std.findall (q _) LQ, std.assert! (LQ = []) "wrong", 29 | std.findall (r _) LR, std.assert! (LR = []) "wrong", 30 | true. -------------------------------------------------------------------------------- /tests/sources/graft_replace_err.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int. 2 | :name "replace_me" 3 | p 1. 4 | 5 | :name "foo" 6 | :replace "replace_me" 7 | p 2. 8 | 9 | main :- fail. -------------------------------------------------------------------------------- /tests/sources/graft_replace_ok.elpi: -------------------------------------------------------------------------------- 1 | :index (1) % "Hash" "DTree" 2 | pred p o:int. 3 | :name "replace_me" 4 | p 1. 5 | 6 | :replace "replace_me" 7 | p 2. 8 | 9 | main :- 10 | std.findall (p _) [p 2], 11 | std.findall (p 1) []. -------------------------------------------------------------------------------- /tests/sources/hdclause.elpi: -------------------------------------------------------------------------------- 1 | kind foo type. 2 | 3 | type a ((int -> foo) -> foo) -> foo. 4 | type b foo -> foo. 5 | 6 | type p (foo -> foo) -> foo -> prop. 7 | type q (foo -> foo) -> foo -> prop. 8 | 9 | p K (a f\ K (f 0)). 10 | q K R :- R = (a f\ K (f 0)). 11 | 12 | main :- 13 | (pi y\ p b (F y)), 14 | (pi y\ q b (F y)), 15 | (pi x y\ q b (F y)), 16 | (pi x y\ p b (F y)). 17 | -------------------------------------------------------------------------------- /tests/sources/heap_discard.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | X = [_,2], 3 | X = [1,2], 4 | not(X = [2,2]), 5 | pi a b\ Y b = [_], b = _. -------------------------------------------------------------------------------- /tests/sources/helena_elpi/Makefile: -------------------------------------------------------------------------------- 1 | H = @ 2 | 3 | ENGINE = ld3_engine.elpi 4 | EXPORT = export-lp2 5 | 6 | ELPI = ../../../elpi 7 | HELENA_DIR = helena 8 | 9 | TEMP = etc/temp.txt 10 | TEST = etc/test_31.txt 11 | 12 | all: 13 | 14 | clean: 15 | $(H)$(RM) -f *~ 16 | 17 | test-tc: 18 | $(H)$(ELPI) -test $(ENGINE) 19 | 20 | test: 21 | $(H)$(ELPI) -no-tc -test $(ENGINE) 22 | 23 | test-31: 24 | $(H)mkdir -p etc 25 | $(H)$(RM) $(TEMP) 26 | $(H)for RUN in `seq 1 31`; do $(ELPI) -no-tc -test $(ENGINE) 2>> $(TEMP); done 27 | $(H)echo `hostname` `date` > $(TEST) 28 | $(H)echo >> $(TEST) 29 | $(H)grep "Time: " $(TEMP) | sort -n -k 2 | cat -n >> $(TEST) 30 | 31 | helena: 32 | $(H)$(MAKE) --no-print-directory -C $(HELENA_DIR) $(EXPORT) 33 | 34 | .PHONY: helena 35 | -------------------------------------------------------------------------------- /tests/sources/helena_elpi/grundlagen_types.elpi: -------------------------------------------------------------------------------- 1 | ../ld-3C/grundlagen_types.elpi -------------------------------------------------------------------------------- /tests/sources/helena_elpi/ld3_engine.elpi: -------------------------------------------------------------------------------- 1 | 2 | accumulate helena. 3 | accumulate grundlagen_types. 4 | accumulate grundlagen_2b_ld3. 5 | 6 | main :- grundlagen. 7 | -------------------------------------------------------------------------------- /tests/sources/helena_elpi/test_31_2nd.txt: -------------------------------------------------------------------------------- 1 | maelstrom Fri Jan 26 12:50:31 CET 2018 2 | 3 | 1 Time: 35.555 4 | 2 Time: 35.570 5 | 3 Time: 35.603 6 | 4 Time: 35.619 7 | 5 Time: 35.624 8 | 6 Time: 35.639 9 | 7 Time: 35.648 10 | 8 Time: 35.649 11 | 9 Time: 35.660 12 | 10 Time: 35.671 13 | 11 Time: 35.680 14 | 12 Time: 35.686 15 | 13 Time: 35.687 16 | 14 Time: 35.696 17 | 15 Time: 35.710 18 | 16 Time: 35.718 * 19 | 17 Time: 35.720 20 | 18 Time: 35.723 21 | 19 Time: 35.725 22 | 20 Time: 35.734 23 | 21 Time: 35.749 24 | 22 Time: 35.770 25 | 23 Time: 35.801 26 | 24 Time: 35.810 27 | 25 Time: 35.842 28 | 26 Time: 36.050 29 | 27 Time: 36.226 30 | 28 Time: 36.494 31 | 29 Time: 38.717 32 | 30 Time: 38.738 33 | 31 Time: 39.547 34 | -------------------------------------------------------------------------------- /tests/sources/hilbert/README: -------------------------------------------------------------------------------- 1 | 2 | Example hilbert: 3 | 4 | This program was written by Dale Miller (modified for testing 5 | purposes). It uses full, third order unification and produces lots of 6 | flex-flex pairs. It is purely of theoretical interest. 7 | 8 | The goal "go." can be called for testing. 9 | 10 | There are two versions: hilbert.sig and hilbert.mod, which are the 11 | original, and hilbert2.sig and hilbert2.mod. 12 | 13 | hilbert2 changes the type for church numerals from 14 | 15 | (i -> i) -> i -> i 16 | 17 | to 18 | 19 | A -> i -> i 20 | 21 | 22 | This has the effect of preventing eta-expansion of terms at certain 23 | key points. Eta-expansion at higher types can lead to the need 24 | to renumber DeBruin indices during reduction. The original version 25 | exhibited a large number of renumbering cases, while the polymorphic 26 | version showed none. 27 | -------------------------------------------------------------------------------- /tests/sources/hilbert/hilbert.sig: -------------------------------------------------------------------------------- 1 | sig hilbert. 2 | kind i type. 3 | 4 | % Notice that there are no constructors for objects in type i. This 5 | % allows you to conclude that the only closed terms of 6 | % (i -> i) -> (i -> i) 7 | % are the Church numerals. 8 | 9 | type zero, one, church ((i -> i) -> (i -> i)) -> o. 10 | 11 | type plus, mult 12 | (((i -> i) -> i -> i) -> ((i -> i) -> i -> i) -> 13 | ((i -> i) -> i -> i)) -> o. 14 | type succ (((i -> i) -> i -> i) -> ((i -> i) -> i -> i)) -> o. 15 | 16 | type problem1 ((i -> i) -> i -> i) -> ((i -> i) -> i -> i) -> 17 | ((i -> i) -> i -> i) -> ((i -> i) -> i -> i) -> o. 18 | 19 | 20 | % added by liang. 21 | type cn int -> ((i -> i) -> (i -> i)) -> o. 22 | type test int -> o. 23 | type go o. 24 | 25 | type main o. 26 | 27 | -------------------------------------------------------------------------------- /tests/sources/hilbert2/README: -------------------------------------------------------------------------------- 1 | 2 | Example hilbert: 3 | 4 | This program was written by Dale Miller (modified for testing 5 | purposes). It uses full, third order unification and produces lots of 6 | flex-flex pairs. It is purely of theoretical interest. 7 | 8 | The goal "go." can be called for testing. 9 | 10 | There are two versions: hilbert.sig and hilbert.mod, which are the 11 | original, and hilbert2.sig and hilbert2.mod. 12 | 13 | hilbert2 changes the type for church numerals from 14 | 15 | (i -> i) -> i -> i 16 | 17 | to 18 | 19 | A -> i -> i 20 | 21 | 22 | This has the effect of preventing eta-expansion of terms at certain 23 | key points. Eta-expansion at higher types can lead to the need 24 | to renumber DeBruin indices during reduction. The original version 25 | exhibited a large number of renumbering cases, while the polymorphic 26 | version showed none. 27 | -------------------------------------------------------------------------------- /tests/sources/hilbert2/hilbert2.sig: -------------------------------------------------------------------------------- 1 | % version with polymorphic types to prevent eta-expansion 2 | 3 | sig hilbert2. 4 | kind i type. 5 | 6 | % Notice that there are no constructors for objects in type i. This 7 | % allows you to conclude that the only closed terms of 8 | % (i -> i) -> (i -> i) 9 | % are the Church numerals. 10 | 11 | type zero, one, church (any -> (i -> i)) -> o. 12 | 13 | type plus, mult 14 | ((any -> i -> i) -> (any -> i -> i) -> 15 | (any -> i -> i)) -> o. 16 | 17 | type succ ((any -> i -> i) -> (any -> i -> i)) -> o. 18 | 19 | type problem1 (any -> i -> i) -> (any -> i -> i) -> 20 | (any -> i -> i) -> (any -> i -> i) -> o. 21 | 22 | 23 | % added by liang. 24 | type cn int -> ((i -> i) -> (i -> i)) -> o. 25 | type test int -> o. 26 | type go o. 27 | 28 | type main o. 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/sources/ho.elpi: -------------------------------------------------------------------------------- 1 | % q(a): OK; q(b): FAIL; q(X): exception; q(a,a): OK; q(true): OK. 2 | 3 | pred q i:(pred). 4 | q(X) :- X. 5 | 6 | pred a. 7 | a. 8 | 9 | main :- q a, q (a,a), q true. 10 | -------------------------------------------------------------------------------- /tests/sources/holp/hc_interp.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * An interpreter for the logic of Horn clauses. This code illustrates 3 | * the usefulness of beta reduction in realizing substitution. Also note 4 | * the use of the logic variable in the third clause for try_clause. 5 | */ 6 | 7 | module hc_interp. 8 | 9 | accumulate lists. 10 | 11 | type backchain (list form) -> form -> o. 12 | type try_clause (list form) -> form -> form -> o. 13 | 14 | hc_interp Cs (ex B) :- !, hc_interp Cs (B T). 15 | hc_interp Cs (B `and C) :- !, hc_interp Cs B, hc_interp Cs C. 16 | hc_interp Cs (B `or C) :- !, (hc_interp Cs B ; hc_interp Cs C). 17 | hc_interp Cs A :- backchain Cs A. 18 | 19 | backchain Cs A :- memb D Cs, try_clause Cs D A. 20 | 21 | try_clause Cs (D1 `and D2) A :- 22 | !, (try_clause Cs D1 A ; try_clause Cs D2 A). 23 | try_clause Cs (all D) A :- !, try_clause Cs (D T) A. 24 | try_clause Cs A A. 25 | try_clause Cs (G `imp A) A :- hc_interp Cs G. 26 | 27 | -------------------------------------------------------------------------------- /tests/sources/holp/hc_interp.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code that implements an interpreter for Horn 3 | * clause logic 4 | */ 5 | 6 | sig hc_interp. 7 | 8 | accum_sig logic_types, logic_basic, logic_vocab. 9 | 10 | type hc_interp (list form) -> form -> o. 11 | 12 | -------------------------------------------------------------------------------- /tests/sources/holp/hc_syntax.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Predicates that recognize goal and clause structure in the logic of 3 | * Horn clauses. This code illustrates how recursion over abstraction 4 | * structure is programmed in Lambda Prolog 5 | */ 6 | 7 | module hc_syntax. 8 | 9 | goal tru. 10 | goal (B `and C) :- goal B, goal C. 11 | goal (B `or C) :- goal B, goal C. 12 | goal (ex C) :- pi X \ ((termp X) => (goal (C X))). 13 | goal A :- atom A. 14 | 15 | def_clause (all C) :- pi X \ ((termp X) => (def_clause (C X))). 16 | def_clause (G `imp A) :- atom A, goal G. 17 | def_clause A :- atom A. 18 | -------------------------------------------------------------------------------- /tests/sources/holp/hc_syntax.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for recognizing formula categories in Horn 3 | * clause logic 4 | */ 5 | 6 | sig hc_syntax. 7 | 8 | accum_sig logic_types, logic_basic. 9 | 10 | /* an `input' predicate---only its definition is used here */ 11 | useonly atom form -> o. 12 | 13 | /* this predicate is used and its definition may be changed */ 14 | type termp term -> o. 15 | 16 | /* `output' predicates---this module supplies their complete definition */ 17 | type goal form -> o. 18 | type def_clause form -> o. 19 | -------------------------------------------------------------------------------- /tests/sources/holp/hcinterp_examples.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A harness for testing an interpreter for a logic programming 3 | * language based on Horn clauses 4 | */ 5 | 6 | module hcinterp_examples. 7 | 8 | accumulate hc_interp. 9 | 10 | accum_sig logic_basic. 11 | 12 | type prog (list form) -> o. 13 | 14 | prog ((adj a b) :: (adj b c) :: (adj c (f c)) :: 15 | (all X\ (all Y\ ((adj X Y) `imp (path X Y)))) :: 16 | (all X\ (all Y\ (all Z\ ( ((adj X Y) `and (path Y Z)) 17 | `imp (path X Z))))) :: nil). 18 | 19 | pathfroma X :- prog Cs, hc_interp Cs (path a X). 20 | 21 | -------------------------------------------------------------------------------- /tests/sources/holp/hcinterp_examples.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a harness for testing an interpreter for 3 | * Horn clause logic 4 | */ 5 | 6 | sig hcinterp_examples. 7 | 8 | accum_sig logic_types, logic_vocab. 9 | 10 | type pathfroma term -> o. 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/sources/holp/hcsyntax_examples.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for code that analyzes the structure of formula 3 | * representation; the particular analysis involves recognizing 4 | * goals and program clauses in Horn clause logic 5 | */ 6 | 7 | module hcsyntax_examples. 8 | 9 | accumulate hc_syntax, refl_syntax. 10 | 11 | /* ex sample formulas */ 12 | formula 1 (ex x \ ((path a x) `and (path x b))). 13 | formula 2 (ex x \ ((path a x) `imp (path x b))). 14 | formula 3 ((path a b) `and (path b a)). 15 | formula 4 ((path a b) `imp (path b a)). 16 | 17 | formula 5 ((path a b) `imp (adj a b)). 18 | formula 6 (all x\ all y\ ((path x y) `imp (adj x y))). 19 | formula 7 (all x\ all y\ (((path x y) `imp (adj x y)) `imp (adj x y))). 20 | 21 | /* testing whether or not one of the formulas above is a goal or a clause */ 22 | test_goal N :- formula N F, goal F. 23 | test_defcl N :- formula N F, def_clause F. 24 | -------------------------------------------------------------------------------- /tests/sources/holp/hcsyntax_examples.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a testing harness for code that checks if formulas satisfy 3 | * the structure of goals or program clauses in Horn clause logic 4 | */ 5 | 6 | sig hcsyntax_examples. 7 | 8 | accum_sig logic_types, logic_basic, logic_vocab. 9 | 10 | type formula int -> form -> o. 11 | 12 | type test_goal, test_defcl int -> o. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/sources/holp/lists.sig: -------------------------------------------------------------------------------- 1 | sig lists. 2 | 3 | kind pairty type -> type -> type. 4 | 5 | type pair A -> B -> (pairty A B). 6 | 7 | exportdef id (list A) -> (list A) -> o. 8 | exportdef memb A -> (list A) -> o. 9 | exportdef member A -> (list A) -> o. 10 | exportdef append (list A) -> (list A) -> (list A) -> o. 11 | exportdef join (list A) -> (list A) -> (list A) -> o. 12 | exportdef assoc A -> B -> (list (pairty A B)) -> o. 13 | exportdef domain (list (pairty A B)) -> (list A) -> o. 14 | exportdef range (list (pairty A B)) -> (list B) -> o. 15 | 16 | -------------------------------------------------------------------------------- /tests/sources/holp/logic_basic.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * This file defines encodings for the logical symbols in a 3 | * first-order logic. 4 | */ 5 | 6 | sig logic_basic. 7 | 8 | accum_sig logic_types. 9 | 10 | /* Constants encoding the logical symbols; note the types of the 11 | generalized quantifiers */ 12 | type perp form. 13 | type tru form. 14 | type (`and) form -> form -> form. 15 | type (`or) form -> form -> form. 16 | type (`imp) form -> form -> form. 17 | type all (term -> form) -> form. 18 | type ex (term -> form) -> form. 19 | -------------------------------------------------------------------------------- /tests/sources/holp/logic_types.sig: -------------------------------------------------------------------------------- 1 | /* The basic categories in our encoding of first-order logic; the sort 2 | term is the type of terms and form is the type of formulas */ 3 | 4 | sig logic_types. 5 | 6 | kind term type. 7 | kind form type. 8 | 9 | -------------------------------------------------------------------------------- /tests/sources/holp/logic_vocab.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * This file defines encodings for the nonlogical symbols in a 3 | * first-order logic 4 | */ 5 | 6 | sig logic_vocab. 7 | 8 | accum_sig logic_types. 9 | 10 | /* The constants and function symbols */ 11 | type a term. 12 | type b term. 13 | type c term. 14 | type f term -> term. 15 | 16 | /* The predicate symbols */ 17 | type path term -> term -> form. 18 | type adj term -> term -> form. 19 | 20 | -------------------------------------------------------------------------------- /tests/sources/holp/main.mod: -------------------------------------------------------------------------------- 1 | module main. 2 | 3 | accumulate hcinterp_examples. 4 | accumulate hcsyntax_examples. 5 | accumulate pnf_examples. 6 | 7 | only_three :- not (pathfroma X, not (X = b), not (X = c), not (X = (f c))). 8 | 9 | main :- pathfroma X, 10 | pathfroma b, 11 | pathfroma c, 12 | pathfroma (f c), 13 | only_three, 14 | test_goal 1, 15 | test_goal 3, 16 | test_defcl 4, 17 | test_defcl 5, 18 | test_defcl 6, 19 | test 1 F1, F1 = ex (x\ path a x `imp tru), 20 | test 2 F2, F2 = all (x\ path a x `imp tru), 21 | test 3 F3, F3 = all (x\ path a x `and path x a), 22 | test 3 F31, F31 = all (x\ all (y\ path a x `and path y a)), 23 | test 3 F32, F32 = all (x\ all (y\ path a y `and path x a)), 24 | test 4 F4, F4 = all (x\ all (y\ path a x `imp path a y)), 25 | test 4 F5, F5 = all (x\ all (y\ path a y `imp path a x)). 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /tests/sources/holp/main.sig: -------------------------------------------------------------------------------- 1 | sig main. 2 | 3 | type main o. 4 | type only_three o. 5 | -------------------------------------------------------------------------------- /tests/sources/holp/pnf.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface for code for transforming formulas into prenex normal form 3 | */ 4 | 5 | sig pnf. 6 | 7 | accum_sig logic_types, logic_basic. 8 | 9 | /* this predicate definition is used but not changed */ 10 | useonly quant_free form -> o. 11 | 12 | /* this definition changes in this module */ 13 | type termp term -> o. 14 | 15 | /* this definition is exported */ 16 | type prenex form -> form -> o. 17 | -------------------------------------------------------------------------------- /tests/sources/holp/pnf_examples.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A harness for testing the transformation of formulas to prenex 3 | * normal form 4 | */ 5 | 6 | module pnf_examples. 7 | 8 | accumulate refl_syntax, pnf. 9 | 10 | type formula int -> form -> o. 11 | 12 | formula 1 ((all (X \ (path a X))) `imp tru). 13 | formula 2 ((ex (X \ (path a X))) `imp tru). 14 | formula 3 ((all (X \ (path a X))) `and (all (Y \ (path Y a)))). 15 | formula 4 ((ex (X \ (path a X))) `imp ((all (Y \ (path a Y))))). 16 | 17 | (test N F) :- (formula N OF), (prenex OF F). 18 | 19 | -------------------------------------------------------------------------------- /tests/sources/holp/pnf_examples.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface for testing the prenex normal form transformer 3 | */ 4 | 5 | sig pnf_examples. 6 | 7 | accum_sig logic_types, logic_basic, logic_vocab. 8 | 9 | /* this predicate definition is used but not changed */ 10 | type test int -> form -> o. 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/sources/holp/refl_syntax.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Predicates for recognizing some categories of quantifier-free expressions 3 | * in a given object logic 4 | */ 5 | 6 | module refl_syntax. 7 | 8 | accum_sig logic_types, logic_basic, logic_vocab. 9 | 10 | type termp term -> o. 11 | type atom form -> o. 12 | type quant_free form -> o. 13 | 14 | /* recognizer for terms */ 15 | termp a. 16 | termp b. 17 | termp c. 18 | termp (f X) :- termp X. 19 | 20 | /* recognizer for atomic formulas */ 21 | atom (path X Y) :- termp X, termp Y. 22 | atom (adj X Y) :- termp X, termp Y. 23 | 24 | /* recognizer for quantifier free formulas */ 25 | quant_free perp. 26 | quant_free tru. 27 | quant_free A :- atom A. 28 | quant_free (B `and C) :- quant_free B, quant_free C. 29 | quant_free (B `or C) :- quant_free B, quant_free C. 30 | quant_free (B `imp C) :- quant_free B, quant_free C. 31 | 32 | -------------------------------------------------------------------------------- /tests/sources/holp/refl_syntax.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for recognizing some categories of quantifier-free 3 | * expressions in a given object logic 4 | */ 5 | 6 | sig refl_syntax. 7 | 8 | accum_sig logic_types, logic_basic, logic_vocab. 9 | 10 | /* recognizer for terms */ 11 | type termp term -> o. 12 | 13 | /* Recognizers for atomic and quantifier free formulas; the exportdef 14 | declaration signifies that the definitions of these predicates is fixed 15 | by this module */ 16 | exportdef atom form -> o. 17 | exportdef quant_free form -> o. 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/sources/hyp_uvar.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred f i:any. 3 | 4 | main :- 5 | (f uvar :- print "ok") ==> (f X, not(f 1)), var X. -------------------------------------------------------------------------------- /tests/sources/ifdef.elpi: -------------------------------------------------------------------------------- 1 | % elpi:if version = 100.0.0 2 | pred pred pred 3 | % elpi:endif 4 | % elpi:if version > 100.0.0 5 | pred pred pred 6 | % elpi:endif 7 | % elpi:if version < 100.0.0 8 | pred x. 9 | x. 10 | % elpi:endif 11 | 12 | % elpi:if version elpi = 100.0.0 13 | pred foo. pred pred. 14 | % elpi:endif 15 | 16 | main :- x. -------------------------------------------------------------------------------- /tests/sources/impl.elpi: -------------------------------------------------------------------------------- 1 | % q X Y shoud yield X=ok Y=ok 2 | 3 | pred f o:diagnostic, o:diagnostic. 4 | symbol a : int. 5 | 6 | q X Y :- (r a => p X), f X Y. 7 | f ok ko :- r a. 8 | f ok ok. 9 | p ko :- r a. 10 | p ok :- r a. 11 | main :- q X Y, X = ok, Y = ok. 12 | -------------------------------------------------------------------------------- /tests/sources/impl2.elpi: -------------------------------------------------------------------------------- 1 | % q X yields X=ok 2 | 3 | pred a. 4 | pred b. 5 | pred c. 6 | 7 | q X :- (a, (b :- a), (a => c)) => (b,c => r ok) => r X. 8 | main :- q X, X = ok. 9 | -------------------------------------------------------------------------------- /tests/sources/impl_prec.elpi: -------------------------------------------------------------------------------- 1 | main :- xx, xx => xx, xx, xx. 2 | main :- std.do! [ xx, pi x\ xx => xx, xx]. 3 | pred xx. 4 | xx. 5 | -------------------------------------------------------------------------------- /tests/sources/impl_prec_ok.elpi: -------------------------------------------------------------------------------- 1 | main :- xx, (xx => xx), xx, xx. 2 | main :- xx, (xx => xx), !. 3 | main :- xx, (xx => (xx,xx)), xx, xx. 4 | main :- std.do! [ xx, xx => xx, xx]. 5 | main :- std.do! [ xx, (pi x\ xx => xx), xx]. 6 | pred xx. 7 | xx. 8 | -------------------------------------------------------------------------------- /tests/sources/io_colon.elpi: -------------------------------------------------------------------------------- 1 | pred f i:int. 2 | main :- (pi i\ f i :- true) => f 1. -------------------------------------------------------------------------------- /tests/sources/is.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | "ab" is "a" ^ "b", 3 | 3 is 2 + 1, 4 | std.findall (X is 1 + 2) L. -------------------------------------------------------------------------------- /tests/sources/lambda.elpi: -------------------------------------------------------------------------------- 1 | % test Z yields Z=impl(impl A B) (impl A B) 2 | 3 | % Type inference for simply typed lambda terms 4 | % Syntax: t ::= appl t t | abs F where F is a function t -> t 5 | % Syntax: ty ::= impl ty ty 6 | 7 | of (appl T1 T2) B :- of T1 (impl A B), of T2 A. 8 | of (lam F) (impl A B) :- pi x\ of x A => of (F x) B. 9 | 10 | test Z :- of (lam f\ lam a\ appl f a) Z. 11 | 12 | kind tm type. 13 | symbol app : tm -> tm -> tm. 14 | symbol lam : (tm -> tm) -> tm. 15 | 16 | kind ty type. 17 | symbol impl : ty -> ty -> ty. 18 | 19 | main :- test Z, Z = impl (impl a b) (impl a b). 20 | -------------------------------------------------------------------------------- /tests/sources/lambda2.elpi: -------------------------------------------------------------------------------- 1 | % q X yields X=ok 2 | 3 | pred p o:int. 4 | 5 | q X :- r X (x\ p x). 6 | r ko (x\ g x). 7 | r ok (y\ p y). 8 | main :- q X, X = ok. 9 | -------------------------------------------------------------------------------- /tests/sources/lambda3.sig: -------------------------------------------------------------------------------- 1 | sig lambda3. 2 | 3 | kind t type. 4 | kind ty type. 5 | kind a type. 6 | 7 | type append (mylist a) -> (mylist a) -> (mylist a) -> o. 8 | type of t -> ty -> o. 9 | type termify (mylist a) -> t -> o. 10 | type impl ty -> ty -> ty. 11 | type appl t -> t -> t. 12 | type lam (t -> t) -> t. 13 | type test t -> o . 14 | type x0 a. 15 | type x1 a. 16 | type x2 a. 17 | type x3 a. 18 | type x4 a. 19 | type x5 a. 20 | type x6 a. 21 | type x7 a. 22 | type x8 a. 23 | type x9 a. 24 | type x10 a. 25 | 26 | kind i type. 27 | type zero i. 28 | type s i -> i. 29 | type plus i -> i -> i -> o. 30 | type mult i -> i -> i -> o. 31 | type exp i -> i -> i -> o. 32 | type iter i -> o -> o. 33 | type once t -> o. 34 | type main o. 35 | 36 | kind mylist type -> type. 37 | type xnil mylist a. 38 | type xcons a -> mylist a -> mylist a. 39 | -------------------------------------------------------------------------------- /tests/sources/lambda4.elpi: -------------------------------------------------------------------------------- 1 | % Test for the correct parsing of binders with types 2 | 3 | pred test1. 4 | test1 :- 5 | X = (x : bool\ x), 6 | Y = X tt, 7 | print Y. 8 | 9 | pred test2. 10 | test2 :- 11 | _ = (x : bool\ x as Z), 12 | Y = Z tt, 13 | print Y. 14 | 15 | main :- 16 | test1, 17 | test2. 18 | -------------------------------------------------------------------------------- /tests/sources/lambda5.elpi: -------------------------------------------------------------------------------- 1 | % Test for the correct parsing of binders with types 2 | % Similar to test lambda4 but with type_checking error 3 | % since the lambda term is applied to a term with 4 | % an unexpected type 5 | 6 | main :- 7 | X = (x : bool\ x), 8 | Y = X 1. % Here type error -------------------------------------------------------------------------------- /tests/sources/lambda6.elpi: -------------------------------------------------------------------------------- 1 | % Test for the correct parsing of binders with types 2 | % Similar to test lambda5 but with type_checking error 3 | % using the as constructor 4 | 5 | main :- 6 | _ = (x : bool\ x as Y), 7 | _ = Y 1. % Here type error -------------------------------------------------------------------------------- /tests/sources/ld-3C/Makefile: -------------------------------------------------------------------------------- 1 | H = @ 2 | 3 | ELPI = elpi 4 | 5 | all: 6 | 7 | test: 8 | $(H)$(ELPI) -no-tc -test ld3c_engine.elpi 9 | 10 | test-tc: 11 | $(H)$(ELPI) -test ld3c_engine.elpi 12 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/grundlagen_pars.elpi: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | 3 | type k+type universe. 4 | type k+set universe. 5 | type k+prop universe. 6 | 7 | type l+0 layer. 8 | type l+1 layer. 9 | type l+2 layer. 10 | 11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 12 | 13 | succ k+set k+type. 14 | succ k+prop k+type. 15 | 16 | has_upsilon l+0. 17 | has_beta l+1. 18 | has_beta l+2. 19 | 20 | prec l+1 l+0. 21 | prec l+2 l+1. 22 | 23 | no_pir. 24 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/ld3c_engine.elpi: -------------------------------------------------------------------------------- 1 | % Engine for \lambda\delta version 3C - engine 2 | 3 | %accumulate ld3c_types. 4 | %accumulate ld3c_trace. 5 | accumulate ld3c_kernel. 6 | accumulate ld3c_global. 7 | 8 | accumulate grundlagen_pars. 9 | %accumulate grundlagen_types. 10 | accumulate grundlagen_2b_ld3. 11 | 12 | type main prop. 13 | main :- grundlagen. 14 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/ld3c_global.elpi: -------------------------------------------------------------------------------- 1 | % Engine for \lambda\delta version 3C - line-based global environment 2 | 3 | type g+line term -> label -> term -> prop. 4 | 5 | kind genv type. 6 | 7 | type gtop genv. 8 | 9 | type gdec+2 term -> genv -> genv. 10 | 11 | type gdef+2 term -> genv -> genv. 12 | 13 | type gv+ genv -> prop. 14 | 15 | % validity predicate (global environment) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 | 17 | % atom 18 | gv+ gtop. 19 | 20 | % global devalaration 21 | gv+ (gdec+2 X G) :- 22 | g+line X L U1, % print L X, 23 | current L => valid_t U1 U2, 24 | ldec X d_rc U2 => gv+ G. 25 | 26 | % global definition 27 | gv+ (gdef+2 X G) :- 28 | g+line X L T1, % print L X, 29 | current L => valid_t T1 T2, 30 | ldef X d_rc T2 => gv+ G. 31 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/ld3c_kernel_1.elpi: -------------------------------------------------------------------------------- 1 | %conv_c X Vs1 M1 X Vs2 M2 :- 2 | % ldef X d_rc T, !, 3 | % conv_rc T Vs1 M1 T Vs2 M2. 4 | 5 | %conv_c X1 Vs1 M1 X2 Vs2 M2 :- 6 | % ldef X1 d_rc T1, ldef X2 d_rc T2, !, 7 | % if (X1 < X2) (conv_sn T1 Vs1 M1 X2 Vs2 M2) (conv_dx X1 Vs1 M1 T2 Vs2 M2). 8 | 9 | %conv_c X1 Vs1 M1 T2 Vs2 M2 :- 10 | % ldef X1 d_rc T1, !, 11 | % conv_sn T1 Vs1 M1 T2 Vs2 M2. 12 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/ld3c_trace.elpi: -------------------------------------------------------------------------------- 1 | % Engine for \lambda\delta version 3C - trace facility 2 | 3 | type current label -> o. 4 | type is_current o. 5 | 6 | is_current :- current c+113. 7 | 8 | valid_c T Vs _ _ :- is_current, 9 | print "VALID_C" "*" T "*" Vs, fail. 10 | 11 | valid_v Vs _ :- is_current, 12 | print "VALID_V" "*" Vs, fail. 13 | 14 | sta_t T D _ :- is_current, 15 | print "STA_T" "*" D ">" T, fail. 16 | 17 | appl_c T Vs Ws D :- is_current, 18 | print "APPL_C" "*" D ">" T "*" Vs "|" Ws, fail. 19 | 20 | conv_c T1 V1s M1 T2 V2s M2 :- is_current, 21 | print "CONV_C" "*" M1 "*" M2 ">" T1 "*" V1s "<->" T2 "*" V2s, fail. 22 | 23 | % applicable Vs T :- is_current, 24 | % print "APPLICABLE" "*" T "*" Vs, fail. 25 | 26 | % castable T U :- is_current, 27 | % print "CASTABLE" "*" T "*" U, fail. 28 | -------------------------------------------------------------------------------- /tests/sources/ld-3C/reductions.tex: -------------------------------------------------------------------------------- 1 | 627154 beta 2 | 5 local ell 3 | 241632 global ell 4 | 2150425 local delta 5 | 314325 global delta 6 | 52 parallel global delta 7 | 3333593 total 8 | 1588652 conversion by alpha 9 | 319837 checked beta 10 | -------------------------------------------------------------------------------- /tests/sources/linear.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | X = Foo_Bar. -------------------------------------------------------------------------------- /tests/sources/list_as_conj.elpi: -------------------------------------------------------------------------------- 1 | type a, b, f prop. 2 | f :- [print a, print b, a]. 3 | a :- (b :- [print "done"]) => b. 4 | a :- (X : list prop). 5 | 6 | main :- f. 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/sources/list_comma.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | L1 = [1,2,3,], 3 | L2 = [1,2,3], 4 | std.length L1 = std.length L2. -------------------------------------------------------------------------------- /tests/sources/llam.sig: -------------------------------------------------------------------------------- 1 | sig llam. 2 | 3 | type main o. 4 | -------------------------------------------------------------------------------- /tests/sources/lyp/Makefile: -------------------------------------------------------------------------------- 1 | H = @ 2 | 3 | ENGINE = lyp_engine.elpi 4 | EXPORT = export-lyp 5 | 6 | ELPI = elpi 7 | HELENA_DIR = helena 8 | 9 | TEMP = etc/temp.txt 10 | TEST = etc/test_31.txt 11 | 12 | all: 13 | 14 | clean: 15 | $(H)$(RM) -f *~ 16 | 17 | test-tc: 18 | $(H)$(ELPI) -test $(ENGINE) 19 | 20 | test: 21 | $(H)$(ELPI) -no-tc -test $(ENGINE) 22 | 23 | test-31: 24 | $(H)mkdir -p etc 25 | $(H)$(RM) $(TEMP) 26 | $(H)for RUN in `seq 1 31`; do $(ELPI) -no-tc -test $(ENGINE) 2>> $(TEMP); done 27 | $(H)echo `hostname` `date` > $(TEST) 28 | $(H)echo >> $(TEST) 29 | $(H)grep "Time: " $(TEMP) | sort -n -k 2 | cat -n >> $(TEST) 30 | 31 | helena: 32 | $(H)$(MAKE) --no-print-directory -C $(HELENA_DIR) $(EXPORT) 33 | 34 | .PHONY: helena 35 | -------------------------------------------------------------------------------- /tests/sources/lyp/lyp_engine.elpi: -------------------------------------------------------------------------------- 1 | % The Formal System λΥP: engine 2 | 3 | % Components %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | accumulate lyp_trace. 6 | accumulate lyp_machine. 7 | accumulate lyp_global. 8 | accumulate grundlagen_2b_lyp. 9 | 10 | % Validation of the Grundlagen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 | 12 | type main prop. 13 | 14 | main :- grundlagen. 15 | -------------------------------------------------------------------------------- /tests/sources/lyp/lyp_global.elpi: -------------------------------------------------------------------------------- 1 | % The Formal System λΥP: signature validation 2 | 3 | % Syntax %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | % annotation: R 6 | kind ann type. 7 | 8 | % signature: G 9 | kind genv type. 10 | 11 | % empty signature 12 | type g_top genv. 13 | 14 | % referred declaration 15 | type g_dec id -> genv -> genv. 16 | 17 | % referred definition 18 | type g_def id -> genv -> genv. 19 | 20 | % specification for referred declaration 21 | type type_g id -> ann -> deg -> term -> prop. 22 | 23 | % specification for referred definition 24 | type cast_g id -> ann -> deg -> term -> term -> prop. 25 | 26 | % Signature Validity %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 27 | 28 | type valid_g genv -> prop. 29 | 30 | valid_g g_top. 31 | 32 | valid_g (g_dec X G) :- 33 | type_g X R D U, %, print R X, 34 | dec_t D U, dec_l X D U => valid_g G. 35 | 36 | valid_g (g_def X G) :- 37 | cast_g X R D U T, %, print R X, 38 | def_t D U T, dec_l X D U => def_l X T => valid_g G. 39 | -------------------------------------------------------------------------------- /tests/sources/lyp/lyp_trace.elpi: -------------------------------------------------------------------------------- 1 | % The Formal System λΥP: trace facility 2 | 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | 5 | % proc_t P T :- print (proc_t P T), fail. 6 | 7 | % expand_t T1 _ :- print (expand_t T1), fail. 8 | 9 | % whd_t T S M _ :- print (whd_t T S M), fail. 10 | 11 | % conv_t T1 S1 S2 T2 :- print (conv_t T1 S1 S2 T2), fail. 12 | 13 | % ac_t T S _ :- print (ac_t T S), fail. 14 | 15 | % sta_t T D _ :- print (sta_t T D), fail. 16 | 17 | % valid_k T :- print (valid_k T), fail. 18 | -------------------------------------------------------------------------------- /tests/sources/lyp/reductions.txt: -------------------------------------------------------------------------------- 1 | 33894 full beta 2 | 4167 restricted beta 3 | 38061 total beta 4 | 509906 delta 5 | 10 parallel delta 6 | 547967 total 7 | 1034313 conversion by alpha 8 | 367766 full checked beta 9 | 31395 restricted checked beta 10 | 399161 total checked beta 11 | -------------------------------------------------------------------------------- /tests/sources/lyp/test_31_1.txt: -------------------------------------------------------------------------------- 1 | monica 2017 Dec 20 23:58 2 | 3 | 1 Time: 9.295 4 | 2 Time: 9.310 5 | 3 Time: 9.312 6 | 4 Time: 9.319 7 | 5 Time: 9.323 8 | 6 Time: 9.325 9 | 7 Time: 9.328 10 | 8 Time: 9.329 11 | 9 Time: 9.330 12 | 10 Time: 9.331 13 | 11 Time: 9.333 14 | 12 Time: 9.334 15 | 13 Time: 9.335 16 | 14 Time: 9.349 17 | 15 Time: 9.354 18 | 16 Time: 9.356 * 19 | 17 Time: 9.360 20 | 18 Time: 9.363 21 | 19 Time: 9.365 22 | 20 Time: 9.366 23 | 21 Time: 9.370 24 | 22 Time: 9.371 25 | 23 Time: 9.378 26 | 24 Time: 9.381 27 | 25 Time: 9.386 28 | 26 Time: 9.390 29 | 27 Time: 9.391 30 | 28 Time: 9.394 31 | 29 Time: 9.403 32 | 30 Time: 9.404 33 | 31 Time: 9.411 34 | -------------------------------------------------------------------------------- /tests/sources/lyp/test_31_2.txt: -------------------------------------------------------------------------------- 1 | maelstrom Tue Jan 9 23:36:25 CET 2018 2 | 3 | 1Time: 9.341 4 | 2Time: 9.342 5 | 3Time: 9.347 6 | 4Time: 9.353 7 | 5Time: 9.356 8 | 6Time: 9.361 9 | 7Time: 9.365 10 | 8Time: 9.366 11 | 9Time: 9.368 12 | 10Time: 9.373 13 | 11Time: 9.375 14 | 12Time: 9.383 15 | 13Time: 9.390 16 | 14Time: 9.392 17 | 15Time: 9.403 18 | 16Time: 9.406 * 19 | 17Time: 9.409 20 | 18Time: 9.415 21 | 19Time: 9.417 22 | 20Time: 9.418 23 | 21Time: 9.427 24 | 22Time: 9.428 25 | 23Time: 9.429 26 | 24Time: 9.439 27 | 25Time: 9.442 28 | 26Time: 9.447 29 | 27Time: 9.451 30 | 28Time: 9.472 31 | 29Time: 9.492 32 | 30Time: 9.509 33 | 31Time: 9.513 34 | -------------------------------------------------------------------------------- /tests/sources/lyp/test_31_3.txt: -------------------------------------------------------------------------------- 1 | monica lun 12 ago 2019, 18.26.40, CEST 2 | 3 | 1 Time: 11.056 4 | 2 Time: 11.082 5 | 3 Time: 11.082 6 | 4 Time: 11.085 7 | 5 Time: 11.087 8 | 6 Time: 11.091 9 | 7 Time: 11.102 10 | 8 Time: 11.109 11 | 9 Time: 11.118 12 | 10 Time: 11.119 13 | 11 Time: 11.121 14 | 12 Time: 11.125 15 | 13 Time: 11.128 16 | 14 Time: 11.135 17 | 15 Time: 11.137 18 | 16 Time: 11.138 * 19 | 17 Time: 11.139 20 | 18 Time: 11.145 21 | 19 Time: 11.148 22 | 20 Time: 11.150 23 | 21 Time: 11.153 24 | 22 Time: 11.158 25 | 23 Time: 11.160 26 | 24 Time: 11.168 27 | 25 Time: 11.177 28 | 26 Time: 11.181 29 | 27 Time: 11.186 30 | 28 Time: 11.199 31 | 29 Time: 11.211 32 | 30 Time: 11.215 33 | 31 Time: 11.281 34 | -------------------------------------------------------------------------------- /tests/sources/macro_type.elpi: -------------------------------------------------------------------------------- 1 | % This test uses the same macro with different types 2 | % The mutable types of the macro should not be affected by side effect 3 | % during the typechecking of the rule for p, otherwise 4 | % the mutable once field would be affected twice with consequent 5 | % fatal error 6 | macro @m A :- X. 7 | 8 | pred p o:(int -> bool). 9 | p (@m). 10 | 11 | pred q o:(string -> int). 12 | q (@m). 13 | 14 | main. -------------------------------------------------------------------------------- /tests/sources/macro_type_err_pos.elpi: -------------------------------------------------------------------------------- 1 | macro @m A :- f A. 2 | 3 | pred f i:int. 4 | 5 | main :- @m "4". -------------------------------------------------------------------------------- /tests/sources/map.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred build i:int, i:int, i:std.map int int, o:std.map int int. 3 | build N N X X :- !. 4 | build N M X X1 :- 5 | N1 is N + 1, 6 | std.map.add N N X XR, 7 | build N1 M XR X1. 8 | 9 | pred test i:int, i:int, i:(pred i:int, i:A, o:int), i:A. 10 | test N N _ _ :- !. 11 | test N M F X :- 12 | N1 is N + 1, 13 | std.assert! (F N X N) "not found", 14 | test N1 M F X. 15 | 16 | pred test2 i:int, i:int, i:(pred i:int, i:A, o:A), i:A. 17 | test2 N N _ _ :- !. 18 | test2 N M F X :- 19 | N1 is N + 1, 20 | std.assert! (F N X X1) "not found", 21 | test2 N1 M F X1. 22 | 23 | macro @iters :- 4096. 24 | 25 | main :- 26 | std.time (build 0 @iters {std.map.make cmp_term} T) Time0, !, 27 | std.time (test 0 @iters std.map.find T) Time1, !, 28 | std.map.bindings T B, 29 | std.assert! ({std.length B} = @iters, B = [pr 0 0|_]) "bindings broken", !, 30 | std.time (test2 0 @iters std.map.remove T) Time2, !, 31 | print Time0 "+" Time1 "+" Time2. -------------------------------------------------------------------------------- /tests/sources/map_ho.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | std.fold {std.iota 9} {std.int.map.empty} (i\std.int.map.add i (x\x)) S, 3 | std.int.map.map S (x\f\r\ pi _\ r = f x) S1, 4 | print S1, 5 | std.fold {std.iota 9} {std.int.map.empty} (i\std.int.map.add i i) S2, 6 | std.int.map.fold S2 0 (x\y\a\r\ r is a + x - y) Sum, 7 | std.assert! (Sum = 0) "wrong fold". -------------------------------------------------------------------------------- /tests/sources/mk-evar-meta.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | (pi x y z\ sigma X XL\ mk-uvar [y] X XL, print "1)" X "/" XL, var XL X [y]). 3 | 4 | 5 | type mk-uvar list A -> B -> C -> o. 6 | mk-uvar L U UL :- declare_constraint (mk-uvar L U UL) [_]. 7 | 8 | constraint mk-uvar { 9 | 10 | rule \ (mk-uvar L U UL) | (meta-mk-uvar L U UL X XL) <=> (U = X, UL = XL). 11 | 12 | } 13 | 14 | type meta-mk-uvar list A -> B -> C -> D -> E -> o. 15 | meta-mk-uvar L (uvar _ _) (uvar _ _) X XL :- X = (uvar D []), XL = (uvar D L). -------------------------------------------------------------------------------- /tests/sources/mu.sig: -------------------------------------------------------------------------------- 1 | sig mu. 2 | 3 | kind e type. 4 | kind mylist type -> type. 5 | 6 | type xnil mylist e. 7 | type xcons e -> mylist e -> mylist e. 8 | type xnil2 mylist (mylist e). 9 | type xcons2 (mylist e) -> mylist (mylist e) -> mylist (mylist e). 10 | type s e -> e. 11 | type zero e. 12 | type m e. 13 | type i e. 14 | type a e. 15 | type u e. 16 | type once o. 17 | type mu o. 18 | type ge e -> e -> o. 19 | type theorem mylist e -> e -> mylist (mylist e) -> o. 20 | type xrule e -> mylist e -> mylist e -> o. 21 | type xrule1 mylist e -> mylist e -> o. 22 | type xrule2 mylist e -> mylist e -> o. 23 | type xrule3 mylist e -> mylist e -> o. 24 | type xrule4 mylist e -> mylist e -> o. 25 | type append mylist e -> mylist e -> mylist e -> o. 26 | type iter e -> o -> o. 27 | type plus e -> e -> e -> o. 28 | type mult e -> e -> e -> o. 29 | type exp e -> e -> e -> o. 30 | type main o. 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/sources/name_builtin.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | (pi f x y\ 3 | name (f x y) f [x, y]), 4 | (pi x\ name x x []), 5 | (pi f x y\ 6 | name (A f x y) f [x,y], print "A=" A, A f x y = (f x y)), 7 | (pi x\ name (B x) x [], print "B=" B, B x = x). 8 | -------------------------------------------------------------------------------- /tests/sources/named_clauses00.elpi: -------------------------------------------------------------------------------- 1 | pred c1. 2 | 3 | :name "name1" 4 | c1. 5 | 6 | :name "name1" 7 | c1. 8 | 9 | main. 10 | -------------------------------------------------------------------------------- /tests/sources/named_clauses01.elpi: -------------------------------------------------------------------------------- 1 | pred c1. 2 | 3 | :before "c" 4 | c1 5 | 6 | main. 7 | -------------------------------------------------------------------------------- /tests/sources/named_clauses02.elpi: -------------------------------------------------------------------------------- 1 | pred c. 2 | 3 | :name "c" 4 | c :- !, fail. 5 | 6 | :before "c" 7 | c :- true. 8 | 9 | :before "c" 10 | c :- !, fail, fail. 11 | 12 | main :- c. 13 | -------------------------------------------------------------------------------- /tests/sources/namespaces00.elpi: -------------------------------------------------------------------------------- 1 | namespace rev { 2 | pred aux i:list A, i:list A, o:list A. 3 | aux [X|XS] ACC R :- aux XS [X|ACC] R. 4 | aux [] L L. 5 | } 6 | pred rev i:list A, o:list A. 7 | rev L RL :- rev.aux L [] RL. 8 | 9 | pred aux i:list A, i:list A, o:list A. 10 | 11 | pred main. 12 | main :- rev [1,2,3] [3,2,1], not(aux [] [] []), rev.aux [] [] []. 13 | -------------------------------------------------------------------------------- /tests/sources/namespaces01.elpi: -------------------------------------------------------------------------------- 1 | pred toto i:int. 2 | toto 1. 3 | 4 | % We test toto is not put inside the namespace 5 | namespace foo { 6 | pred bar i:any. 7 | bar X :- toto 2 => baz X. 8 | pred baz i:any. 9 | baz X :- toto X. 10 | } 11 | main :- foo.bar 2, foo.baz 1. 12 | 13 | -------------------------------------------------------------------------------- /tests/sources/namespaces02.elpi: -------------------------------------------------------------------------------- 1 | namespace x { 2 | namespace acc { accumulate namespaces00. } 3 | pred rev.aux i:list int, i:list int, o:list int. 4 | foo :- rev.aux [] [] []. % does not exists, since it is inside acc 5 | } 6 | 7 | main :- x.acc.rev [1,2,3] [3,2,1], x.acc.rev.aux [] [] [], not(x.foo). 8 | -------------------------------------------------------------------------------- /tests/sources/namespaces03.elpi: -------------------------------------------------------------------------------- 1 | type a.foo4 prop. 2 | type a.foo3 prop. 3 | type a.foo2 prop. 4 | type a.foo1 prop. 5 | type a.b.foo2 prop. 6 | type a.b.foo1 prop. 7 | type a.b.c.foo prop. 8 | 9 | namespace a { 10 | 11 | foo1 :- b.c.foo. 12 | foo2 :- b.foo1, b.foo2. 13 | 14 | namespace b { 15 | 16 | foo1 :- c.foo. 17 | 18 | namespace c { 19 | 20 | foo. 21 | 22 | } 23 | 24 | foo2 :- c.foo. 25 | 26 | } 27 | 28 | foo3 :- b.c.foo. 29 | foo4 :- b.foo1, b.foo2. 30 | 31 | } 32 | 33 | main :- a.foo1, a.foo2, a.foo3, a.foo4. 34 | -------------------------------------------------------------------------------- /tests/sources/nil_cons.elpi: -------------------------------------------------------------------------------- 1 | main :- [] = nil, 3 :: [] = cons 3 []. 2 | -------------------------------------------------------------------------------- /tests/sources/notation.elpi: -------------------------------------------------------------------------------- 1 | module test. 2 | /* 3 | infixl x+,y+ 190. 4 | infixr x++ 191. 5 | prefixr z+ 191. 6 | postfixl w+ 190. 7 | infixl x* 200. 8 | */ 9 | X +x D. 10 | 11 | foo xx uu. 12 | 13 | ~z x ?w. 14 | 15 | x *x y +x z *x w. 16 | 17 | a +x b +x c +x d +x e. 18 | a ++x b ++x c ++x d ++x e. 19 | 20 | type a, b, d, x, xx, w, y, z, c, cd, e, uu prop. 21 | type f prop -> prop. 22 | type g list prop -> prop. 23 | type foo prop -> prop -> prop. 24 | type (~z) prop -> prop. 25 | type (?w) prop -> prop. 26 | type (+x) prop -> prop -> prop. 27 | type (++x) prop -> prop -> prop. 28 | type (+y) A -> B -> C. 29 | type (*x) A -> B -> C. 30 | 31 | main :- print (f a +x g [b] +y d), cd +x d. 32 | 33 | -------------------------------------------------------------------------------- /tests/sources/notation_error.elpi: -------------------------------------------------------------------------------- 1 | infix foo 1. -------------------------------------------------------------------------------- /tests/sources/oc_eta.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | pi w \ f (y\ X y) w = X w, print X. 3 | 4 | type f (A -> A) -> A -> A. -------------------------------------------------------------------------------- /tests/sources/patternunif.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | 3 | pred q o:(tm -> tm -> tm -> prop). 4 | 5 | % q Y should yield Y = \\\f 2 6 | q Y :- pi b\ pi c\ (r :- pi a\ s (f a) => s (X b c a)) => r, Y = X. 7 | 8 | main :- q Y, Y = x\y\z\f z. 9 | -------------------------------------------------------------------------------- /tests/sources/patternunif2.elpi: -------------------------------------------------------------------------------- 1 | % r Y yields Y=\0 2 | pred q o:(int -> int), o:(int -> int). 3 | q (a\ X a) X. 4 | r A :- pi c\ q (a\a) A. 5 | 6 | main :- r Y, Y = x\x. 7 | -------------------------------------------------------------------------------- /tests/sources/pcf/control.mod: -------------------------------------------------------------------------------- 1 | module control. 2 | 3 | %pred if i:prop, i:prop, i:prop. 4 | type once o -> o. 5 | 6 | 7 | % Relates three formulas if the corresponding condition holds: 8 | % ``if Cond Then Else'' attempts to prove Then if the condition Cond 9 | % success; otherwise it attempts Else. Notice the use of !. 10 | 11 | % if Cond Then Else :- Cond, !, Then. 12 | % if Cond Then Else :- Else. 13 | 14 | % Attempts to prove its argument and if it succeeds, backtracking is 15 | % disallowed by using !. 16 | 17 | once P :- P, !. 18 | 19 | type announce o -> o. 20 | 21 | announce G :- 22 | print ">> ", term_to_string G String, print String, print "\n", fail. 23 | 24 | 25 | type spi o -> o. 26 | 27 | spi G :- 28 | (print ">Entering ", term_to_string G Str, print Str, print "\n", G, 29 | print ">Success ", term_to_string G Strx, print Strx, print "\n"; 30 | print ">Leaving ", term_to_string G Str, print Str, print "\n", fail). 31 | -------------------------------------------------------------------------------- /tests/sources/pcf/control.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Some special control predicates of general utility 3 | */ 4 | 5 | sig control. 6 | 7 | exportdef announce o -> o. % for displaying goals 8 | exportdef spi o -> o. % display entry and exit from goal 9 | exportdef if o -> o -> o -> o. % if then else 10 | exportdef once o -> o. % once only predicate 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/eval.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to the call-by-value interpreter for PCF 3 | */ 4 | 5 | sig eval. 6 | 7 | accum_sig pcf. 8 | 9 | %type special tm -> int -> list tm -> tm. 10 | 11 | type eval tm -> tm -> o. 12 | -------------------------------------------------------------------------------- /tests/sources/pcf/eval_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the call-by-value evaluator for PCF 3 | */ 4 | 5 | module eval_test. 6 | 7 | accumulate eval, examples. 8 | 9 | type eval_test int -> tm -> o. 10 | 11 | eval_test 1 V :- prog "fib" Fib, eval (Fib # in 12) V. 12 | eval_test 2 V :- prog "map" Map, prog "fib" Fib, 13 | eval (Map # Fib # (lcons # in 3 # (lcons # in 6 # empty))) V. 14 | eval_test 3 V :- prog "app" App, 15 | eval (App # (lcons # in 3 # empty) # (lcons # in 5 # empty)) V. 16 | eval_test 4 V :- prog "mem" Mem, 17 | eval (Mem # (in 3) # (lcons # in 5 # (lcons # in 3 # empty))) V. 18 | eval_test 5 V :- prog "mem" Mem, 19 | eval (Mem # (in 4) # (lcons # in 5 # (lcons # in 3 # empty))) V. 20 | 21 | 22 | -------------------------------------------------------------------------------- /tests/sources/pcf/eval_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to the testing harness for the call-by-value interpreter 3 | */ 4 | 5 | sig eval_test. 6 | 7 | accum_sig eval. 8 | 9 | exportdef eval_test int -> tm -> o. 10 | 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/examples.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a collection of terms illustrating the encoding of 3 | * programs in a simple functional programming language 4 | */ 5 | 6 | sig examples. 7 | 8 | accum_sig pcf. 9 | 10 | exportdef prog string -> tm -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/mono_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for code that infers monotypes for programs in 3 | * the simple functional programming language 4 | */ 5 | 6 | module mono_test. 7 | 8 | accumulate monoinfer, examples. 9 | 10 | type mono_test string -> ty -> o. 11 | 12 | mono_test String Type :- prog String Term, infer Term Type. 13 | -------------------------------------------------------------------------------- /tests/sources/pcf/mono_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface for testing code that infers monomorphic types for 3 | * programs in the simple functional programming language 4 | */ 5 | 6 | sig mono_test. 7 | 8 | accum_sig monoinfer, monotypes. 9 | 10 | type mono_test string -> ty -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/monoinfer.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for inferring monotypes for programs 3 | * in the simple functional programming language 4 | */ 5 | 6 | sig monoinfer. 7 | 8 | accum_sig pcf, monotypes. 9 | 10 | type infer tm -> ty -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/monotypes.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Encoding of types. Polymorphism is not explicitly represented in 3 | * types in this encoding; some aspects of polymorphism can be 4 | * captured through logic variables in the meta-logic. This encoding 5 | * is in a sense a shallow encoding. 6 | */ 7 | 8 | sig monotypes. 9 | 10 | kind ty type. % constructor for mono types 11 | 12 | type (-->) ty -> ty -> ty. % arrow type constructor 13 | 14 | type lst ty -> ty. % list type constructor 15 | type num ty. % integer type 16 | type bool ty. % boolean type 17 | -------------------------------------------------------------------------------- /tests/sources/pcf/pcf.mod: -------------------------------------------------------------------------------- 1 | /* combines script1 to script4. 2 | */ 3 | 4 | module pcf. 5 | 6 | 7 | accumulate eval_test, mono_test, poly_test, tr_test, examples. 8 | 9 | type main o. 10 | 11 | main :- % std.spy(eval_test 1 V1), !, 12 | % std.spy(eval_test 2 V2), !, 13 | % std.spy(eval_test 3 V3), !, 14 | % V1 = in 144, 15 | % V2 = (lcons # in 2 # (lcons # in 8 # empty)), 16 | % V3 = (lcons # in 3 # (lcons # in 5 # empty)), 17 | std.spy(mono_test "onep" Ty1), !, 18 | std.spy(mono_test "is_sym" Ty2), !, 19 | std.spy(mono_test "fib" Ty3), !, 20 | std.spy(poly_test "successor" Ty4), !, 21 | std.spy(poly_test "onep" Ty5), !, 22 | std.spy(poly_test "is_sym" Ty6), !, 23 | std.spy(tr_test "successor"), !, 24 | std.spy(tr_test "onep"), !, 25 | std.spy(tr_test "is_sym"). 26 | -------------------------------------------------------------------------------- /tests/sources/pcf/pcf.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * The sorts and constants needed for encoding the terms in a simple 3 | * functional programming language PCF 4 | */ 5 | 6 | sig pcf. 7 | 8 | kind tm type. 9 | 10 | type fn (tm -> tm) -> tm. % abstraction constructor 11 | 12 | type (#) tm -> tm -> tm. % application constructor 13 | 14 | type fixpt (tm -> tm) -> tm. % fixed point constructor for recursion 15 | type cond tm -> tm -> tm -> tm. % conditional 16 | type in int -> tm. % constructor for embedding integers 17 | 18 | type and, or, false, truth, % boolean functions 19 | car, cdr, lcons, nullp, consp, empty, % lists functions 20 | equal, greater, zerop, minus, plus, times % integer functions 21 | tm. 22 | 23 | type main o. 24 | -------------------------------------------------------------------------------- /tests/sources/pcf/poly_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the code that infers polytypes for programs 3 | * in the simple functional programming language. 4 | */ 5 | 6 | module poly_test. 7 | 8 | accumulate polyinfer, examples. 9 | 10 | type poly_test string -> poly -> o. 11 | 12 | poly_test String Ty :- prog String T, polyinfer T Ty. 13 | -------------------------------------------------------------------------------- /tests/sources/pcf/poly_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface for testing code that infers polytypes for programs 3 | * in the simple functional programming language 4 | */ 5 | 6 | sig poly_test. 7 | 8 | accum_sig polyinfer, polytypes. 9 | 10 | type poly_test string -> poly -> o. 11 | 12 | -------------------------------------------------------------------------------- /tests/sources/pcf/polyinfer.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for inferring polytypes for programs 3 | * in the simple functional programming language 4 | */ 5 | 6 | sig polyinfer. 7 | 8 | accum_sig pcf, polytypes. 9 | 10 | type polyinfer tm -> poly -> o. 11 | 12 | -------------------------------------------------------------------------------- /tests/sources/pcf/polytypes.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Representing polytypes. Uses monotypes as the base, reflecting these 3 | * into the encoding through a special constructor and adding 4 | * quantification. No type variables are assumed to appear in types at 5 | * this level. 6 | */ 7 | 8 | sig polytypes. 9 | 10 | accum_sig monotypes. 11 | 12 | kind poly type. 13 | 14 | type all (ty -> poly) -> poly. 15 | type c ty -> poly. 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/sources/pcf/refl_syntax.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Code for recognizing the terms representing valid programs in the 3 | * simple functional programming language that is considered here 4 | */ 5 | 6 | module refl_syntax. 7 | 8 | accum_sig pcf. 9 | 10 | type term tm -> o. 11 | 12 | term (fn R) :- pi X\ ((term X) => (term (R X))). 13 | term (M # N) :- term M, term N. 14 | term (fixpt R) :- pi X\((term X) => (term (R X))). 15 | term (cond M N P) :- term M, term N, term P. 16 | 17 | term (in X). 18 | 19 | term and. 20 | term or. 21 | term false. 22 | term truth. 23 | term car. 24 | term cdr. 25 | term lcons. 26 | term nullp. 27 | term consp. 28 | term empty. 29 | term equal. 30 | term greater. 31 | term zerop. 32 | term minus. 33 | term plus. 34 | term times. 35 | 36 | -------------------------------------------------------------------------------- /tests/sources/pcf/refl_syntax.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a recognizer of valid program terms 3 | */ 4 | 5 | sig refl_syntax. 6 | 7 | accum_sig pcf. 8 | 9 | /* the definition of this predicate may need to be dynamically extended */ 10 | type term tm -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/tailrec.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Recognizing tail recursive functions of arbitrary arguments. 3 | * This code illustrates the use of Lambda Prolog scoping devices in 4 | * realizing recursion over binding structure 5 | */ 6 | 7 | module tailrec. 8 | 9 | accumulate refl_syntax. 10 | 11 | type tailrec tm -> o. 12 | type trfn tm -> o. 13 | type headrec tm -> o. 14 | type trbody tm -> o. 15 | 16 | tailrec (fixpt M) :- !, pi F\ ((headrec F) => (trfn (M F))). 17 | tailrec M. 18 | 19 | trfn (fn R) :- pi X\ ((term X) => (trfn (R X))). 20 | trfn R :- trbody R. 21 | 22 | trbody (cond M N P) :- term M, trbody N, trbody P. 23 | trbody (M # N) :- !, trbody M, term N. 24 | trbody M :- headrec M; term M. 25 | 26 | -------------------------------------------------------------------------------- /tests/sources/pcf/tailrec.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for recognizing tail recursiveness of arbitrary 3 | * arity functions 4 | */ 5 | 6 | sig tailrec. 7 | 8 | accum_sig pcf. 9 | 10 | type term tm -> o. 11 | 12 | exportdef tailrec tm -> o. 13 | 14 | -------------------------------------------------------------------------------- /tests/sources/pcf/tr_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the code that checks for tail recursiveness 3 | * of programs in the simple functional programming language. 4 | */ 5 | 6 | module tr_test. 7 | 8 | accumulate tailrec, examples. 9 | 10 | type tr_test string -> o. 11 | 12 | tr_test String :- prog String T, tailrec T. 13 | -------------------------------------------------------------------------------- /tests/sources/pcf/tr_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface for testing code that checks for tail recursiveness 3 | * of programs in the simple functional programming language 4 | */ 5 | 6 | sig tr_test. 7 | 8 | accum_sig tailrec. 9 | 10 | type tr_test string -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/pcf/unifytypes.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for unifying types. Types are assumed to be 3 | * represented like monotypes, i.e. without explicit quantification, 4 | * with one exception: variables are not represented by meta variables 5 | * but, rather, by special constants of which the predicate tvar is true. 6 | */ 7 | 8 | sig unifytypes. 9 | 10 | accum_sig monotypes. 11 | 12 | % predicate for encoding type variables 13 | type tvar ty -> o. 14 | 15 | % Representation of disagreement pairs 16 | kind eq type. 17 | type (===) ty -> ty -> eq. 18 | 19 | % (unify Eqs In Out) is true if solving the equations represented by 20 | % Eqs results in In being instantiated to Out 21 | type unify list eq -> ty -> ty -> o. 22 | 23 | -------------------------------------------------------------------------------- /tests/sources/pi.elpi: -------------------------------------------------------------------------------- 1 | % q X yields X=ok 2 | type z int -> int -> diagnostic -> prop. 3 | q X :- pi x\ p x => pi y\ r y => z x y X. 4 | z A B ko :- r A, p B. 5 | z A B ok :- p A, r B. 6 | main :- q X, X = ok. 7 | -------------------------------------------------------------------------------- /tests/sources/pi3.elpi: -------------------------------------------------------------------------------- 1 | % q X yields X=\0, i.e. X=b\b 2 | 3 | pred z o:any. 4 | pred q o:any. 5 | q X :- pi x\ pi y\ z (w\ X). 6 | z (a\ a). 7 | z (a\ b\ b). 8 | 9 | main :- q X, X = b\b. 10 | -------------------------------------------------------------------------------- /tests/sources/pi5.elpi: -------------------------------------------------------------------------------- 1 | % q X, r X, s X all yields X=ok 2 | kind i type. 3 | type lam, bam (i -> i) -> i. 4 | type of i -> prop. 5 | type stop i. 6 | type s diagnostic -> prop. 7 | type r diagnostic -> prop. 8 | type q diagnostic -> prop. 9 | 10 | of stop. 11 | of (bam x\x). 12 | of (lam x\F) :- pi w\ of F. 13 | 14 | q X :- of (lam x\ bam y\ y), X = ok. 15 | r X :- of (bam y\ y), X = ok. 16 | s X :- of (lam x\ lam y\ stop), X = ok. 17 | 18 | main :- q X, r S, s T, X = ok, S = ok, T = ok. 19 | -------------------------------------------------------------------------------- /tests/sources/pm.elpi: -------------------------------------------------------------------------------- 1 | type f int -> prop. 2 | type a int. 3 | 4 | main :- 5 | pattern_match (f X) (f 1), 6 | print X, 7 | not(pattern_match (f a) (f Y)), 8 | print Y. -------------------------------------------------------------------------------- /tests/sources/printer.elpi: -------------------------------------------------------------------------------- 1 | symbol r : int -> prop. 2 | symbol r : int -> int. 3 | symbol r : int -> string. 4 | symbol f : int -> int. 5 | symbol f : int -> string. 6 | symbol g : int -> int. 7 | symbol g : int -> string. 8 | symbol (&&) : int -> int -> int. 9 | symbol (||) : int -> int -> int. 10 | symbol (===>) : int -> int -> int. 11 | main :- 12 | print (p X :- (q X : prop), (r x:prop)), % BUG 13 | print (X is f Y mod r X), 14 | print (X is f Y + r X * g A), 15 | print (X is (f Y + r X) * g A), 16 | print (X1 is f Y ^ r X ^ g A), 17 | print (X || A && B ===> G), 18 | print [(f X : int), g Y, (a + b), a + b]. -------------------------------------------------------------------------------- /tests/sources/progs/curry_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A harness for testing the code implementing the `currying' transform 3 | */ 4 | 5 | module curry_test. 6 | 7 | accumulate terms, curry_transform. 8 | 9 | type test int -> tm -> o. 10 | 11 | test 1 CurriedF :- trm trfact2 F, curry F CurriedF. 12 | -------------------------------------------------------------------------------- /tests/sources/progs/curry_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to the tester of the `currying' transformer 3 | */ 4 | 5 | sig curry_test. 6 | 7 | accum_sig fp_types, fp_vocab. 8 | 9 | exportdef test int -> tm -> o. 10 | -------------------------------------------------------------------------------- /tests/sources/progs/curry_transform.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A program for transforming a function that takes two arguments as 3 | * a pair into a function of two arguments; the second function is, thus 4 | * a curried version of the first. All of this computation is done through 5 | * higher-order unification and beta reduction (for substitution) 6 | */ 7 | 8 | module curry_transform. 9 | 10 | type curry tm -> tm -> o. 11 | 12 | curry (fix F \ (abs X \ (A (fst X) (snd X) (prp X) 13 | (R \ S \ (app F (pr R S)))))) 14 | (fix F \ (abs Y \ (abs Z \ (A Y Z truth 15 | (R \ S \ (app (app F R) S)))))). 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/sources/progs/curry_transform.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for transforming a function that takes a pair as 3 | * argument into an equivalent one that takes two separate arguments 4 | */ 5 | 6 | sig curry_transform. 7 | 8 | accum_sig fp_vocab, fp_types. 9 | 10 | exportdef curry tm -> tm -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/progs/eval.sig: -------------------------------------------------------------------------------- 1 | sig eval. 2 | 3 | accum_sig fp_types, fp_vocab. 4 | 5 | type eval tm -> tm -> o. 6 | -------------------------------------------------------------------------------- /tests/sources/progs/eval_basic.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A call-by-value evaluator for the pure lambda calculus. Observe how 3 | * substitution is realized simply as (Lambda Prolog) application in the 4 | * second clause for eval. 5 | */ 6 | 7 | module eval_basic. 8 | 9 | eval (abs R) (abs R). 10 | eval (app M N) V :- eval M (abs R), eval N U, eval (R U) V. 11 | 12 | -------------------------------------------------------------------------------- /tests/sources/progs/eval_basic.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Signature for a (barebones) call-by-value evaluator for the lambda 3 | * calculus 4 | */ 5 | 6 | sig eval_basic. 7 | 8 | accum_sig fp_types. 9 | 10 | type eval tm -> tm -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/progs/eval_examples.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the interpreter (written in Lambda Prolog) for 3 | * the functional programming language under consideration 4 | */ 5 | 6 | module eval_examples. 7 | 8 | accumulate eval, terms. 9 | 10 | type test int -> tm -> o. 11 | 12 | test 1 FactOf5 :- trm trfact1 F, eval (app (app F (c 5)) (c 1)) FactOf5. 13 | 14 | test 2 Gcd :- trm gcd2 F, eval (app (app F (c 5)) (c 1)) Gcd. 15 | 16 | test 3 Gcd :- trm gcd2 F, eval (app (app F (c 5)) (c 35)) Gcd. 17 | 18 | test 4 Gcd :- trm gcd2 F, eval (app (app F (c 33)) (c 9)) Gcd. 19 | 20 | test 5 App :- trm appnd F, eval (app (app F (lcons (c 1) (lcons (c 2) null))) 21 | (lcons (c 3) (lcons (c 4) null))) 22 | App. 23 | -------------------------------------------------------------------------------- /tests/sources/progs/eval_examples.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to the testing harness for the interpreter for the functional 3 | * programming language 4 | */ 5 | 6 | sig eval_examples. 7 | 8 | accum_sig fp_types, fp_vocab. 9 | 10 | type eval tm -> tm -> o. 11 | exportdef test int -> tm -> o. 12 | -------------------------------------------------------------------------------- /tests/sources/progs/fp_types.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * The sorts and constants needed for encoding the terms in the 3 | * untyped lambda calculus 4 | */ 5 | 6 | sig fp_types. 7 | 8 | kind tm type. 9 | 10 | type abs (tm -> tm) -> tm. 11 | type app tm -> tm -> tm. 12 | 13 | -------------------------------------------------------------------------------- /tests/sources/progs/general_tr.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Recognizing tail recursive functions of arbitrary arguments. 3 | * This code illustrates the use of Lambda Prolog scoping devices in 4 | * realizing recursion over binding structure 5 | */ 6 | 7 | module general_tr. 8 | 9 | accumulate refl_syntax. 10 | 11 | type tailrec tm -> o. 12 | type trfn tm -> o. 13 | type headrec tm -> o. 14 | type trbody tm -> o. 15 | 16 | tailrec (fix M) :- pi F\ ((headrec F) => (trfn (M F))). 17 | 18 | trfn (abs R) :- pi X\ ((term X) => (trfn (R X))). 19 | trfn R :- trbody R. 20 | 21 | trbody (cond M N P) :- term M, trbody N, trbody P. 22 | trbody M :- term M ; headrec M. 23 | 24 | headrec (app M N) :- headrec M, term N. 25 | -------------------------------------------------------------------------------- /tests/sources/progs/general_tr.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for recognizing tail recursiveness of arbitrary 3 | * arity functions 4 | */ 5 | 6 | sig general_tr. 7 | 8 | accum_sig fp_types, fp_vocab. 9 | 10 | type term tm -> o. 11 | 12 | exportdef tailrec tm -> o. 13 | 14 | -------------------------------------------------------------------------------- /tests/sources/progs/progs.mod: -------------------------------------------------------------------------------- 1 | module progs. 2 | 3 | accumulate progs1. 4 | accumulate progs2. 5 | accumulate progs3. 6 | accumulate progs4. 7 | 8 | main :- main1, main2, main3, main4. 9 | 10 | -------------------------------------------------------------------------------- /tests/sources/progs/progs.sig: -------------------------------------------------------------------------------- 1 | sig progs. 2 | 3 | type main o. 4 | -------------------------------------------------------------------------------- /tests/sources/progs/progs1.sig: -------------------------------------------------------------------------------- 1 | sig progs1. 2 | 3 | type main1 o. 4 | -------------------------------------------------------------------------------- /tests/sources/progs/progs2.mod: -------------------------------------------------------------------------------- 1 | module progs2. 2 | 3 | accumulate curry_test. 4 | 5 | main2 :- 6 | %--- script2 --- 7 | test 1 F6, F6 = fix (x1\ abs (x2\ abs (x3\ Dummy x2 x3 truth (x4\ x5\ app (app x1 x4) x5)))). 8 | 9 | 10 | /* 11 | The remaining disagreement pairs list: 12 | <_T1 (fst #1) (snd #1) (prp #1) (W1\ W2\ app #2 (pr W1 W2)), cond (&& (prp #1) (eq (fst #1) (c 0))) (snd #1) (cond (prp #1) (app #2 (pr (minus (fst #1) (c 1)) (times (fst #1) (snd #1)))) err)> 13 | */ 14 | -------------------------------------------------------------------------------- /tests/sources/progs/progs2.sig: -------------------------------------------------------------------------------- 1 | sig progs2. 2 | 3 | type main2 o. 4 | -------------------------------------------------------------------------------- /tests/sources/progs/progs3.mod: -------------------------------------------------------------------------------- 1 | module progs3. 2 | 3 | accumulate tr1_test. 4 | 5 | main3 :- 6 | %--- script3 --- 7 | test_nb 1, test_nb 2, not (test_nb 3). 8 | 9 | -------------------------------------------------------------------------------- /tests/sources/progs/progs3.sig: -------------------------------------------------------------------------------- 1 | sig progs3. 2 | 3 | type main3 o. 4 | -------------------------------------------------------------------------------- /tests/sources/progs/progs4.mod: -------------------------------------------------------------------------------- 1 | module progs4. 2 | 3 | accumulate tr2_test. 4 | 5 | main4 :- 6 | %--- script4 --- 7 | test_nb 1, test_nb 2, not (test_nb 3), test_nb 4. 8 | 9 | -------------------------------------------------------------------------------- /tests/sources/progs/progs4.sig: -------------------------------------------------------------------------------- 1 | sig progs4. 2 | 3 | type main4 o. 4 | -------------------------------------------------------------------------------- /tests/sources/progs/refl_syntax.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Code for recognizing the terms representing valid programs in the 3 | * simple functional programming language that is considered here 4 | */ 5 | 6 | module refl_syntax. 7 | 8 | type term tm -> o. 9 | 10 | term (abs R) :- pi X\ ((term X) => (term (R X))). 11 | term (app M N) :- term M, term N. 12 | term (cond M N P) :- term M, term N, term P. 13 | term (fix R) :- pi X\((term X) => (term (R X))). 14 | 15 | term truth. 16 | term false. 17 | term (c X). 18 | term null. 19 | term (lcons Hd Tl) :- term Hd, term Tl. 20 | 21 | term (M && N) :- term M, term N. 22 | term (plus M N) :- term M, term N. 23 | term (minus M N) :- term M, term N. 24 | term (times M N) :- term M, term N. 25 | term (lss M N) :- term M, term N. 26 | term (eq M N) :- term M, term N. 27 | term (intp M) :- term M. 28 | term (pr M N) :- term M, term N. 29 | term (prp M) :- term M. 30 | term (fst M) :- term M. 31 | term (snd M) :- term M. 32 | term (nullp L) :- term L. 33 | term (hd L) :- term L. 34 | term (tl L) :- term L. 35 | term err. 36 | -------------------------------------------------------------------------------- /tests/sources/progs/refl_syntax.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a recognizer of valid program terms 3 | */ 4 | 5 | sig refl_syntax. 6 | 7 | accum_sig fp_types, fp_vocab. 8 | 9 | /* the definition of this predicate may need to be dynamically extended */ 10 | type term tm -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/progs/terms.mod: -------------------------------------------------------------------------------- 1 | % Some example (encodings of) functions in the functional programming 2 | % language 3 | 4 | module terms. 5 | 6 | trm trfact1 (fix F \ (abs N\ (abs M\ 7 | (cond (eq N (c 0)) M 8 | (app (app F (minus N (c 1))) (times N M)))))). 9 | 10 | trm trfact2 (fix F \ (abs P \ 11 | (cond ((prp P) && (eq (fst P) (c 0))) (snd P) 12 | (cond (prp P) (app F (pr (minus (fst P) (c 1)) 13 | (times (fst P) (snd P)))) 14 | err)))). 15 | 16 | 17 | 18 | trm gcd2 (fix Gcd\ (abs X\ (abs Y\ 19 | (cond (eq (c 1) X) (c 1) 20 | (cond (lss X Y) ((app (app Gcd Y) X)) 21 | (cond (eq X Y) X 22 | (app (app Gcd (minus X Y)) Y))))))). 23 | 24 | trm appnd (fix Appnd\ (abs L1\ (abs L2\ 25 | (cond (nullp L1) L2 26 | (lcons (hd L1) (app (app Appnd (tl L1)) L2)))))). 27 | 28 | -------------------------------------------------------------------------------- /tests/sources/progs/terms.sig: -------------------------------------------------------------------------------- 1 | sig terms. 2 | 3 | accum_sig fp_types, fp_vocab. 4 | 5 | kind namex type. 6 | 7 | type trm namex -> tm -> o. 8 | 9 | type trfact1 namex. 10 | type trfact2 namex. 11 | type gcd2 namex. 12 | type appnd namex. 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/sources/progs/tr1_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the code in tr_recognizer that contains the 3 | * definition of a predicate for recognizing tail recursiveness of 4 | * two argument functions 5 | */ 6 | 7 | module tr1_test. 8 | 9 | accumulate terms, tr_recognizer. 10 | 11 | type test_nb int -> o. 12 | 13 | test_nb 1 :- trm trfact1 F, tl_rec F. 14 | 15 | test_nb 2 :- trm gcd2 F, tl_rec F. 16 | 17 | test_nb 3 :- trm appnd F, tl_rec F. 18 | 19 | -------------------------------------------------------------------------------- /tests/sources/progs/tr1_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to a tester for a tail recursion recognizer for functions 3 | * of two arguments 4 | */ 5 | 6 | sig tr1_test. 7 | 8 | accum_sig fp_types, fp_vocab. 9 | 10 | exportdef test int -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/progs/tr2_test.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * A testing harness for the general tail recursion recognizing program 3 | */ 4 | 5 | module tr2_test. 6 | 7 | accumulate terms, general_tr. 8 | 9 | type test_nb int -> o. 10 | 11 | test_nb 1 :- trm trfact1 F, tailrec F. 12 | 13 | test_nb 2 :- trm gcd2 F, tailrec F. 14 | 15 | test_nb 3 :- trm appnd F, tailrec F. 16 | 17 | test_nb 4 :- trm trfact2 F, tailrec F. 18 | 19 | -------------------------------------------------------------------------------- /tests/sources/progs/tr2_test.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for testing the predicate for recognizing 3 | * tail recursiveness of arbitrary arity functions 4 | */ 5 | 6 | sig tr2_test. 7 | 8 | accum_sig fp_types, fp_vocab, terms. 9 | 10 | kind namex type. 11 | 12 | exportdef test int -> o. 13 | 14 | exportdef trm namex -> tm -> o. 15 | 16 | -------------------------------------------------------------------------------- /tests/sources/progs/tr_recognizer.mod: -------------------------------------------------------------------------------- 1 | /* 2 | * Code for recognizing tail recursive functions of two arguments. 3 | * This program illustrates the power of higher-order unification. 4 | */ 5 | 6 | module tr_recognizer. 7 | 8 | type tl_rec tm -> o. 9 | 10 | tl_rec (fix F\ (abs X\ (abs Y\ (H X Y)))). 11 | 12 | tl_rec (fix F\ (abs X\ (abs Y\ (app (app F (G X Y)) (H X Y))))). 13 | 14 | tl_rec (fix F\ (abs X\ (abs Y\ 15 | (cond (C X Y) (H F X Y) (G F X Y))))) :- 16 | tl_rec (fix F\ (abs X\ (abs Y\ (H F X Y)))), 17 | tl_rec (fix F\ (abs X\ (abs Y\ (G F X Y)))). 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /tests/sources/progs/tr_recognizer.sig: -------------------------------------------------------------------------------- 1 | /* 2 | * Interface to code for recognizing tail recursiveness of two 3 | * argument functions 4 | */ 5 | 6 | sig tr_recognizer. 7 | 8 | accum_sig fp_types, fp_vocab. 9 | 10 | exportdef tl_rec tm -> o. 11 | 12 | -------------------------------------------------------------------------------- /tests/sources/queens.sig: -------------------------------------------------------------------------------- 1 | % ?- queens(4, Qs). 2 | % produces 3 | % Qs = [3,1,4,2] ; 4 | % Qs = [2,4,1,3] 5 | 6 | % queens +int -[int] 7 | 8 | sig queens. 9 | 10 | kind i type. 11 | 12 | kind mylist type -> type. 13 | type xnil mylist i. 14 | type xcons i -> mylist i -> mylist i. 15 | 16 | type spy o -> o. 17 | 18 | type xxx mylist i -> o. 19 | type iter i -> o -> o. 20 | type once o. 21 | 22 | type zero i. 23 | type s i -> i. 24 | type plus i -> i -> i -> o. 25 | type mult i -> i -> i -> o. 26 | type exp i -> i -> i -> o. 27 | type less i -> i -> o. 28 | type neq i -> i -> o. 29 | type queens i -> (mylist i) -> o. 30 | type queens_aux (mylist i) -> (mylist i) -> (mylist i) -> o. 31 | type range i -> i -> (mylist i) -> o. 32 | type not_attack_aux (mylist i) -> i -> o. 33 | type not_attack (mylist i) -> i -> i -> o. 34 | type select (mylist i) -> (mylist i) -> i -> o. 35 | type q mylist i -> o. 36 | type main o. 37 | 38 | -------------------------------------------------------------------------------- /tests/sources/quote_syntax.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | quote_syntax "src/builtin.elpi" "main" A B, print B. -------------------------------------------------------------------------------- /tests/sources/random.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | random.self_init, 3 | random.int 10 R, 4 | print R, 5 | R >= 0, 6 | R < 10. 7 | -------------------------------------------------------------------------------- /tests/sources/reduce_cbn.sig: -------------------------------------------------------------------------------- 1 | sig reduce_cbn. 2 | 3 | kind t type. 4 | 5 | type main o. 6 | type app t -> t -> t. 7 | type lam (t -> t) -> t. 8 | type copy t -> t -> o. 9 | type cbn t -> t -> o. 10 | type subst (t -> t) -> t -> t -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/reduce_cbv.sig: -------------------------------------------------------------------------------- 1 | sig reduce_cbv. 2 | 3 | kind t type. 4 | 5 | type main o. 6 | type app t -> t -> t. 7 | type lam (t -> t) -> t. 8 | type copy t -> t -> o. 9 | type cbv t -> t -> o. 10 | type beta t -> t -> t -> o. 11 | -------------------------------------------------------------------------------- /tests/sources/restriction.elpi: -------------------------------------------------------------------------------- 1 | % main should fail. 2 | 3 | main :- (x\ x) = (x\ X). 4 | -------------------------------------------------------------------------------- /tests/sources/restriction3.elpi: -------------------------------------------------------------------------------- 1 | kind term type. 2 | pred foo o:term, o:term. 3 | 4 | type debug-print string -> A -> prop. 5 | debug-print A B :- print A B. 6 | 7 | pred spy i:prop. 8 | spy P :- counter "run" NR, if (not(NR = 0)) (debug-print "run=" NR) true, 9 | debug-print "----<<---- enter: " P, 10 | P, !, 11 | debug-print "---->>---- exit: " P. 12 | spy P :- debug-print "---->>---- fail: " P, fail. 13 | 14 | type lam (term -> term) -> term. 15 | 16 | foo A B :- 17 | spy(A = lam i\ lam j\ X_ i j), 18 | spy(B = lam i\ lam j\ Y_ i j), 19 | spy(A = lam i\ lam j\ i), 20 | spy(B = lam i\ lam j\ i). 21 | 22 | main :- pi x\ foo (A_ x) B_. 23 | -------------------------------------------------------------------------------- /tests/sources/restriction4.elpi: -------------------------------------------------------------------------------- 1 | type f int -> (int -> int) -> int. 2 | 3 | main :- 4 | pi x\ sigma Y Z\ pi y\ 5 | std.spy(X x = f (Y y) e\ (Z y e)). -------------------------------------------------------------------------------- /tests/sources/restriction5.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | pi x y z u w\ 3 | std.spy(X x y = X u w). -------------------------------------------------------------------------------- /tests/sources/restriction6.elpi: -------------------------------------------------------------------------------- 1 | type f int -> (int -> int -> int) -> int. 2 | main :- 3 | pi x\ sigma Y\ pi y\ sigma Z\ 4 | std.spy(X x = f (Y y) l\e\ (Z e)). -------------------------------------------------------------------------------- /tests/sources/rev14.mod: -------------------------------------------------------------------------------- 1 | module rev14. 2 | 3 | rev L RL :- aux L xnil RL . 4 | aux xnil L L . 5 | aux (xcons X XS) ACC R :- aux XS (xcons X ACC) R . 6 | 7 | append xnil L L . 8 | append (xcons X XS) L (xcons X L1) :- append XS L L1 . 9 | 10 | 11 | main :- 12 | X1 = (xcons x1 (xcons x2 (xcons x3 (xcons x4 (xcons x5 (xcons x6 (xcons x7 (xcons x8 (xcons x9 (xcons x10 xnil)))))))))), 13 | append X1 X1 X2 , 14 | append X2 X2 X3 , 15 | append X3 X3 X4 , 16 | append X4 X4 X5 , 17 | append X5 X5 X6 , 18 | append X6 X6 X7 , 19 | append X7 X7 X8 , 20 | append X8 X8 X9 , 21 | append X9 X9 X10 , 22 | append X10 X10 X11 , 23 | append X11 X11 X12 , 24 | append X12 X12 X13 , 25 | append X13 X13 X14 , 26 | % append X14 X14 X15 , 27 | % append X15 X15 X16 , 28 | % append X16 X16 X17 , 29 | % append X17 X17 X18 , 30 | X = X14 , 31 | rev X Y, rev Y Z, X = Z. 32 | 33 | -------------------------------------------------------------------------------- /tests/sources/rev14.sig: -------------------------------------------------------------------------------- 1 | sig rev14. 2 | 3 | kind t type. 4 | kind l type. 5 | type x1 t. 6 | type x2 t. 7 | type x3 t. 8 | type x4 t. 9 | type x5 t. 10 | type x6 t. 11 | type x7 t. 12 | type x8 t. 13 | type x9 t. 14 | type x10 t. 15 | type rev l -> l -> o. 16 | type append l -> l -> l -> o. 17 | type aux l -> l -> l -> o. 18 | type main o. 19 | type xnil l. 20 | type xcons t -> l -> l. 21 | -------------------------------------------------------------------------------- /tests/sources/same_term.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | 3 == 3, 3 | not([X, _] == [X, Y]), 4 | not(X == Y), 5 | (x\ x) == (y\ y), 6 | ID = (x\x), 7 | (ID 3) == (ID 3), 8 | pi x y\ same_var (X x) (X y), not(same_term (X x) (X y)). -------------------------------------------------------------------------------- /tests/sources/self_assignment.elpi: -------------------------------------------------------------------------------- 1 | % main should succeed 2 | 3 | kind tm type. 4 | symbol d : tm. 5 | 6 | q X X A. 7 | 8 | main :- (pi c\ q X A Y, q Y A X, q X Y A), X = d. 9 | -------------------------------------------------------------------------------- /tests/sources/sepcomp1.ml: -------------------------------------------------------------------------------- 1 | let us = [{| 2 | 3 | pred p. 4 | main :- p. 5 | 6 | |}; {| 7 | 8 | p :- print "ok". 9 | 10 | |}; ] 11 | ;; 12 | 13 | let () = Sepcomp.Sepcomp_template.main us;; -------------------------------------------------------------------------------- /tests/sources/sepcomp2.ml: -------------------------------------------------------------------------------- 1 | let us = [{| 2 | 3 | pred p. 4 | main :- p. 5 | 6 | |}; {| 7 | 8 | pred p. 9 | p :- print "ok". 10 | 11 | |}; ] 12 | ;; 13 | 14 | let () = Sepcomp.Sepcomp_template.main us;; -------------------------------------------------------------------------------- /tests/sources/sepcomp3.ml: -------------------------------------------------------------------------------- 1 | let us = [{| 2 | 3 | main :- p. 4 | 5 | pred p. 6 | 7 | :name "xxx" 8 | p :- print "one". 9 | 10 | |}; {| 11 | 12 | :name "xxx" 13 | p :- print "two". 14 | 15 | |}; ] 16 | ;; 17 | 18 | let () = Sepcomp.Sepcomp_template.main us;; -------------------------------------------------------------------------------- /tests/sources/sepcomp4.ml: -------------------------------------------------------------------------------- 1 | let us = [{| 2 | 3 | main :- p 1. 4 | 5 | pred p o:int. 6 | 7 | |}; {| 8 | 9 | pred p i:int. 10 | 11 | p X :- print X. 12 | 13 | |}; ] 14 | ;; 15 | 16 | let () = Sepcomp.Sepcomp_template.main us;; -------------------------------------------------------------------------------- /tests/sources/sepcomp5.ml: -------------------------------------------------------------------------------- 1 | let u = {| 2 | 3 | type x int. 4 | type y int. 5 | pred p i:int. 6 | main :- p x. 7 | 8 | |} 9 | ;; 10 | 11 | let () = 12 | let open Sepcomp.Sepcomp_template in 13 | let elpi = init () in 14 | let flags = Elpi.API.Compile.default_flags in 15 | let _, u = cc ~elpi ~flags ~base:(Elpi.API.Compile.empty_base ~elpi) 0 u in 16 | Marshal.to_channel (open_out_bin "_log/sepcomp5.unit") u []; 17 | exit 0 18 | -------------------------------------------------------------------------------- /tests/sources/sepcomp6.ml: -------------------------------------------------------------------------------- 1 | let u = {| 2 | 3 | type y int. 4 | type x int. 5 | 6 | pred p i:int. 7 | 8 | p x :- print "ok". 9 | p _ :- print "ko". 10 | 11 | |}; 12 | ;; 13 | 14 | let () = 15 | let open Sepcomp.Sepcomp_template in 16 | let open Elpi.API in 17 | let elpi = init () in 18 | let flags = Compile.default_flags in 19 | let u0 = Marshal.from_channel (open_in_bin "_log/sepcomp5.unit") in 20 | let _, u1 = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 0 u in 21 | let p = List.fold_left (fun base u -> Compile.extend ~base u) (Compile.empty_base ~elpi) [u0;u1] in 22 | exec (query ~elpi p) 23 | -------------------------------------------------------------------------------- /tests/sources/sepcomp7.ml: -------------------------------------------------------------------------------- 1 | let u = {| 2 | 3 | pred p i:int. 4 | 5 | :name "this" p 1. 6 | 7 | |} 8 | ;; 9 | 10 | let () = 11 | let open Sepcomp.Sepcomp_template in 12 | let open Elpi.API in 13 | let elpi = init () in 14 | let flags = Compile.default_flags in 15 | let _, u = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 0 u in 16 | Marshal.to_channel (open_out_bin "_log/sepcomp7.unit") u []; 17 | exit 0 18 | -------------------------------------------------------------------------------- /tests/sources/sepcomp8.ml: -------------------------------------------------------------------------------- 1 | let u = {| 2 | 3 | pred p i:int. 4 | :remove "this" p _. 5 | 6 | p 2. 7 | 8 | |} 9 | ;; 10 | 11 | let () = 12 | let open Sepcomp.Sepcomp_template in 13 | let open Elpi.API in 14 | let elpi = init () in 15 | let flags = Compile.default_flags in 16 | let u0 = Marshal.from_channel (open_in_bin "_log/sepcomp7.unit") in 17 | let base = Compile.extend ~flags ~base:(Compile.empty_base ~elpi) u0 in 18 | let _,u = cc ~elpi ~flags ~base 0 u in 19 | Marshal.to_channel (open_out_bin "_log/sepcomp8.unit") u []; 20 | exit 0 21 | -------------------------------------------------------------------------------- /tests/sources/sepcomp9.ml: -------------------------------------------------------------------------------- 1 | let u = {| 2 | 3 | main :- not(p 1), p 2. 4 | 5 | |}; 6 | ;; 7 | 8 | let () = 9 | let open Sepcomp.Sepcomp_template in 10 | let open Elpi.API in 11 | let elpi = init () in 12 | let flags = Compile.default_flags in 13 | let u0 = Marshal.from_channel (open_in_bin "_log/sepcomp7.unit") in 14 | let u1 = Marshal.from_channel (open_in_bin "_log/sepcomp8.unit") in 15 | let p = List.fold_left (fun base u -> Compile.extend ~base u) (Compile.empty_base ~elpi) [u0;u1] in 16 | let _,u2 = cc ~elpi ~flags ~base:p 0 u in 17 | let p = List.fold_left (fun base u -> Compile.extend ~base u) p [u2] in 18 | exec (query ~elpi p) 19 | -------------------------------------------------------------------------------- /tests/sources/sepcomp_tyid.ml: -------------------------------------------------------------------------------- 1 | let p1 = {| 2 | pred p o:int. 3 | p 1. 4 | |} 5 | 6 | let p2 = {| 7 | pred p o:int. 8 | p 2. 9 | |} 10 | 11 | let maine = "pred p o:int. main :- std.findall (p _) L, print L." 12 | 13 | open Elpi.API 14 | 15 | let () = 16 | let open Sepcomp.Sepcomp_template in 17 | let elpi = init () in 18 | let flags = Compile.default_flags in 19 | let pmain,_ = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 1 maine in 20 | let _,unit1 = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 2 p1 in 21 | let _,unit2 = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 3 p2 in 22 | 23 | let cp = Compile.extend ~base:pmain unit1 in 24 | let cp = Compile.extend ~base:cp unit2 in 25 | 26 | let q = Compile.query cp (Parse.goal_from ~elpi ~loc:(Ast.Loc.initial "g") (Lexing.from_string "main")) in 27 | exec q 28 | -------------------------------------------------------------------------------- /tests/sources/sepcomp_tyid2.ml: -------------------------------------------------------------------------------- 1 | let p1 = {| 2 | pred p o:int. 3 | p 1. 4 | |} 5 | 6 | let p2 = {| 7 | pred p o:int. 8 | p 2. 9 | |} 10 | 11 | let maine = "pred p o:int. main :- std.findall (p _) L, print L." 12 | 13 | open Elpi.API 14 | 15 | let () = 16 | let open Sepcomp.Sepcomp_template in 17 | let elpi = init () in 18 | let flags = Compile.default_flags in 19 | let pmain,_ = cc ~elpi ~flags ~base:(Compile.empty_base ~elpi) 1 maine in 20 | let pmain,_ = cc ~elpi ~flags ~base:pmain 2 p1 in 21 | let pmain,_ = cc ~elpi ~flags ~base:pmain 3 p2 in 22 | 23 | let q = Compile.query pmain (Parse.goal_from ~elpi ~loc:(Ast.Loc.initial "g") (Lexing.from_string "main")) in 24 | 25 | exec q 26 | -------------------------------------------------------------------------------- /tests/sources/set.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred build i:int, i:int, i:std.set int, o:std.set int. 3 | build N N X X :- !. 4 | build N M X X1 :- 5 | N1 is N + 1, 6 | std.set.add N X XR, 7 | build N1 M XR X1. 8 | 9 | pred test i:int, i:int, i:(pred i:int, i:A), i:A. 10 | test N N _ _ :- !. 11 | test N M F X :- 12 | N1 is N + 1, 13 | std.assert! (F N X) "not found", 14 | test N1 M F X. 15 | 16 | pred test2 i:int, i:int, i:(pred i:int, i:A, o:A), i:A, o:A. 17 | test2 N N _ R R :- !. 18 | test2 N M F X R :- 19 | N1 is N + 1, 20 | F N X X1, 21 | test2 N1 M F X1 R. 22 | 23 | macro @iters :- 4096. 24 | 25 | main :- 26 | std.time (build 0 @iters {std.set.make cmp_term} T) Time0, !, 27 | std.time (test 0 @iters std.set.mem T) Time1, !, 28 | std.set.elements T L, 29 | std.assert! ({std.length L} = @iters, L = [0|_]) "elements broken", !, 30 | std.time (test2 0 @iters std.set.remove T E) Time2, !, 31 | std.assert! (std.set.cardinal E 0) "not empty", 32 | print Time0 "+" Time1 "+" Time2. -------------------------------------------------------------------------------- /tests/sources/set_ho.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | std.fold {std.iota 99999} {std.int.set.empty} std.int.set.add S, 3 | std.time (std.int.set.filter S (x\0 is x mod 123) S1) T1, 4 | std.int.set.cardinal S1 N, 5 | std.time (std.filter {std.int.set.elements S} (x\0 is x mod 123) L, std.fold L {std.int.set.empty} std.int.set.add S2) T2, 6 | std.int.set.cardinal S2 M, 7 | std.assert! (N = M) "wrong card filter", 8 | std.int.set.fold S1 0 (x\a\r\ r is a + x) Sum, 9 | std.assert! (Sum = 40599594) "wrong fold", 10 | print T1 " < " T2, 11 | std.int.set.map S1 (_\r\ r = 1) S3, 12 | std.assert! (std.int.set.cardinal S3 1) "wrong card map". -------------------------------------------------------------------------------- /tests/sources/shorten.elpi: -------------------------------------------------------------------------------- 1 | 2 | namespace b { 3 | 4 | pred foo. 5 | foo :- true. 6 | pred baz. 7 | baz :- fail. 8 | 9 | namespace bar { 10 | 11 | pred baz. 12 | baz :- foo. 13 | 14 | } 15 | 16 | 17 | shorten bar.{ baz }. 18 | 19 | } 20 | 21 | namespace a { 22 | 23 | shorten b.{ foo }. 24 | shorten b.bar.{ baz }. 25 | 26 | pred main. 27 | main :- foo, b.foo, baz, bar.baz, b.bar.baz. 28 | 29 | pred bar.baz. 30 | bar.baz :- true. 31 | 32 | shorten b.{ baz }. 33 | 34 | baz :- true. 35 | bar.baz :- baz. 36 | 37 | } 38 | 39 | main :- a.main. 40 | 41 | -------------------------------------------------------------------------------- /tests/sources/shorten2.elpi: -------------------------------------------------------------------------------- 1 | accumulate shorten_aux, shorten_aux2. 2 | 3 | pred foo. 4 | foo :- true. 5 | 6 | main :- 7 | foo, bar. 8 | -------------------------------------------------------------------------------- /tests/sources/shorten_aux.elpi: -------------------------------------------------------------------------------- 1 | namespace a { 2 | pred foo. 3 | foo :- !, fail. 4 | } 5 | 6 | shorten a.{ foo }. 7 | -------------------------------------------------------------------------------- /tests/sources/shorten_aux2.elpi: -------------------------------------------------------------------------------- 1 | pred bar. 2 | bar :- foo. 3 | -------------------------------------------------------------------------------- /tests/sources/shorten_builtin.elpi: -------------------------------------------------------------------------------- 1 | shorten std.string.set.{ empty }. 2 | 3 | main :- 4 | print {empty}. -------------------------------------------------------------------------------- /tests/sources/shorten_trie.elpi: -------------------------------------------------------------------------------- 1 | pred std.list.map o:any, i:any. 2 | std.list.map _ _. 3 | pred std.string.concat1 i:any, i:any, o:any. 4 | std.string.concat1 _ _ _. 5 | pred std.string.escape i:any, o:any. 6 | std.string.escape _ _. 7 | 8 | shorten std.{list.map, string.{ concat1, escape }}. 9 | 10 | main :- list.map F [], concat1 "a" "b" AB, escape "x y" E. 11 | -------------------------------------------------------------------------------- /tests/sources/spill-var.elpi: -------------------------------------------------------------------------------- 1 | pred iterate i:(pred i:A, o:A), i:A, o:(list A). 2 | iterate F X [X|XS] :- iterate F {F X} XS ; XS = []. 3 | 4 | main. -------------------------------------------------------------------------------- /tests/sources/spill2.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | typeabbrev stack (list tm). 3 | 4 | pred whd i:tm, i:stack, o:tm, o:stack. 5 | whd X [] X []. 6 | 7 | pred unwind i:tm, i:stack, o:tm. 8 | unwind X [] X. 9 | 10 | pred do i:list prop. 11 | do [P] :- P. 12 | 13 | % main :- ( whd X [] A B, unwind A B Y : list prop ). 14 | main :- do [ unwind {whd X []} Y ]. 15 | % main :- ( unwind {whd X []} Y : prop ). -------------------------------------------------------------------------------- /tests/sources/spill_and.elpi: -------------------------------------------------------------------------------- 1 | kind term type. 2 | type app term -> term -> term. 3 | type lam (term -> term) -> term. 4 | type t term. 5 | 6 | func copy term -> term. 7 | copy (app A B) (app A1 B1) :- copy A A1, copy B B1. 8 | copy (lam F) (lam F1) :- pi x\ copy x x => copy (F x) (F1 x). 9 | % we omit (copy x x) on purpose 10 | 11 | main :- 12 | %T = (lam x\ {copy x t => ((A x) = x, copy (app (A x) x))}), 13 | print T, 14 | T = (lam _\ app t t). 15 | -------------------------------------------------------------------------------- /tests/sources/spill_collision.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | type lam (tm -> list tm) -> tm. 3 | 4 | main :- 5 | pi x\ std.do! [ 6 | pi x a \ F x = (lam y\ [lam w\{std.append [x] [y]}]) 7 | ]. -------------------------------------------------------------------------------- /tests/sources/spill_impl.elpi: -------------------------------------------------------------------------------- 1 | kind term type. 2 | type app term -> term -> term. 3 | type lam (term -> term) -> term. 4 | type t term. 5 | 6 | pred copy i:term, o:term. 7 | copy (app A B) (app A1 B1) :- copy A A1, copy B B1. 8 | copy (lam F) (lam F1) :- pi x\ copy (F x) (F1 x). 9 | % we omit (copy x x) on purpose 10 | 11 | main :- 12 | T = (lam x\ {copy x t => copy (app x x)}), 13 | print T, 14 | T = (lam _\ app t t). 15 | -------------------------------------------------------------------------------- /tests/sources/spill_in_list.elpi: -------------------------------------------------------------------------------- 1 | pred p i:A, o:A. 2 | p X X. 3 | 4 | pred print-list i:list A. 5 | print-list []. 6 | print-list [X|XS] :- print X, print-list XS. 7 | 8 | main :- 9 | std.do! [ 10 | CL = [], 11 | print-list {std.map CL p}, 12 | ]. -------------------------------------------------------------------------------- /tests/sources/spill_lam.elpi: -------------------------------------------------------------------------------- 1 | pred pp i:int, o:string. 2 | pp X "name" :- name X. 3 | 4 | main :- (X = x\ print {pp x}), (X = x\ sigma W\ pp x W, print W). 5 | -------------------------------------------------------------------------------- /tests/sources/spill_or.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int, o:int. 2 | pred q o:int, o:int. 3 | q 2 3. 4 | p X X. 5 | 6 | main :- (fail ; (p {q 2} X)), !, X == 3. -------------------------------------------------------------------------------- /tests/sources/spill_pi.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | pi x\ print {std.append [x] []}. -------------------------------------------------------------------------------- /tests/sources/spill_sigma.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | typeabbrev stack (list tm). 3 | 4 | pred whd i:tm, i:stack, o:tm, o:stack. 5 | whd X [] X []. 6 | 7 | pred unwind i:tm, i:stack, o:tm. 8 | unwind X [] X. 9 | 10 | pred do i:list prop. 11 | do [P] :- P. 12 | 13 | % main :- ( whd X [] A B, unwind A B Y : list prop ). 14 | main :- pi x\ sigma W\ unwind {whd X []} Y. 15 | % main :- ( unwind {whd X []} Y : prop ). -------------------------------------------------------------------------------- /tests/sources/tc_ambiguous.elpi: -------------------------------------------------------------------------------- 1 | symbol a : int -> int. 2 | symbol a : bool -> int. 3 | symbol a : bool -> bool. 4 | 5 | main :- 3 = a F. -------------------------------------------------------------------------------- /tests/sources/toyml/ast.ml: -------------------------------------------------------------------------------- 1 | type pos = Lexing.position = { 2 | pos_fname : string; 3 | pos_lnum : int; 4 | pos_bol : int; 5 | pos_cnum : int; 6 | } 7 | [@@deriving show, ord, eq] 8 | type position = pos * pos [@@deriving show, ord, eq] 9 | 10 | type term = 11 | | Const of string (* global name or bound variable *) 12 | | Int of int (* literals *) 13 | | App of ast * ast 14 | | Lam of string * ast 15 | | Let of string * ast * ast 16 | | Eq of ast * ast 17 | and ast = { loc : position; v : term } 18 | [@@deriving show] 19 | 20 | type tye = 21 | | Var of string 22 | | Integer 23 | | Boolean 24 | | Arrow of tye * tye 25 | | List of tye 26 | | Pair of tye * tye 27 | [@@deriving show] 28 | 29 | type quantification = 30 | | Any 31 | | EqualityType 32 | [@@deriving show] 33 | 34 | type typ = 35 | | All of string * quantification * typ 36 | | Mono of tye 37 | [@@deriving show] 38 | -------------------------------------------------------------------------------- /tests/sources/toyml/dune.disabled: -------------------------------------------------------------------------------- 1 | (executable 2 | (name toyml) 3 | (modules ast lexer parser pmap toyml) 4 | (preprocess (per_module ((pps ppx_deriving.std) ast))) 5 | (libraries elpi ppx_deriving.std)) 6 | 7 | (ocamllex lexer) 8 | (ocamlyacc parser) -------------------------------------------------------------------------------- /tests/sources/toyml/input: -------------------------------------------------------------------------------- 1 | 3 = 2 2 | (fun x -> x) = (fun x -> x) 3 | let id x = x in id [] 4 | let id x = x in (id [], id 1) 5 | let refl x = x = x in refl [] 6 | let refl x = x = x in refl (fun x -> x) 7 | let card x = size (undup x) in card [] 8 | let f y = let g x = (x,y) in g y in f 1 9 | size 1 10 | [1] = (1,1) 11 | -------------------------------------------------------------------------------- /tests/sources/toyml/lexer.mll: -------------------------------------------------------------------------------- 1 | (* File lexer.mll *) 2 | { 3 | open Parser (* The type token is defined in parser.mli *) 4 | exception Eof 5 | } 6 | rule token = parse 7 | [' ' '\t' '\n'] { token lexbuf } (* skip blanks *) 8 | | ['0'-'9']+ as lxm { INT(int_of_string lxm) } 9 | | "let" { LET } 10 | | "in" { IN } 11 | | "fun" { LAM } 12 | | ['a'-'z']+ as lxm { IDENT lxm } 13 | | '(' { LPAREN } 14 | | ')' { RPAREN } 15 | | '[' { LBRK } 16 | | ']' { RBRK } 17 | | '=' { EQ } 18 | | ',' { COMMA } 19 | | ';' { SEMICOLON } 20 | | "->" { ARROW } 21 | | eof { EOF } 22 | -------------------------------------------------------------------------------- /tests/sources/toyml/pmap.ml: -------------------------------------------------------------------------------- 1 | module type T = sig 2 | type t 3 | val hash : t -> int 4 | end 5 | 6 | module Make(X : T) = struct 7 | module M = Map.Make(struct 8 | type t = int 9 | let compare x y = x - y 10 | end) 11 | type 'a t = (X.t * 'a) list M.t 12 | let empty = M.empty 13 | let add k v m = 14 | let h = X.hash k in 15 | try 16 | let l = M.find h m in 17 | let l = List.remove_assq k l in 18 | M.add h ((k,v) :: l) m 19 | with Not_found -> 20 | M.add h [k,v] m 21 | let find_opt k m = 22 | try 23 | let h = Hashtbl.hash k in 24 | let l = M.find h m in 25 | Some (List.assq k l) 26 | with Not_found -> None 27 | 28 | end 29 | -------------------------------------------------------------------------------- /tests/sources/trace-w/hm.elpi: -------------------------------------------------------------------------------- 1 | pred of i:term, o:ty. 2 | 3 | % terms 4 | of (app H A) (mono T) :- 5 | of H (mono (S ===> T)), 6 | of A (mono S). 7 | 8 | of (lam F) (mono (S ===> T)) :- 9 | pi x\ of x (mono S) => of (F x) (mono T). 10 | 11 | of (let E PT B) (mono TB) :- 12 | of E (mono T), 13 | gammabar (mono T) PT, 14 | pi x\ of x PT => of (B x) (mono TB). 15 | 16 | of (eq LHS RHS) (mono bool) :- 17 | of LHS (mono T), 18 | of RHS (mono T), 19 | eqbar T. 20 | 21 | of X (mono T) :- of X (all E Poly), specialize (all E Poly) T. 22 | 23 | -------------------------------------------------------------------------------- /tests/sources/trace.elpi: -------------------------------------------------------------------------------- 1 | pred p i:int, o:int. 2 | p 1 1 :- 1 is 2 + 3. 3 | p 1 2 :- X = 1, Y = 2, X = Y. 4 | p 2 3. 5 | 6 | main :- 7 | p 1 X_ ; p 2 Y_. -------------------------------------------------------------------------------- /tests/sources/trace2.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | print 1, (pi x\ sigma Y\ fail => (true, fail)). -------------------------------------------------------------------------------- /tests/sources/trace3.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred p o:int, o:int. 3 | p 1 1. 4 | p 2 2. 5 | p 3 3 :- fail. 6 | p 4 1. 7 | p 4 2. 8 | p 4 3 :- fail. 9 | p 5 3. 10 | 11 | 12 | main :- p X_ 3. -------------------------------------------------------------------------------- /tests/sources/trace4.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred p o:int, o:int. 3 | p 1 1. 4 | p 2 2. 5 | p 3 3 :- fail. 6 | p 4 1. 7 | p 4 2. 8 | p 4 4. 9 | 10 | 11 | main :- p X_ 3 ; true. -------------------------------------------------------------------------------- /tests/sources/trace_chr.elpi: -------------------------------------------------------------------------------- 1 | constraint even odd { 2 | rule \ (even X) (odd X) | (odd z) <=> true. 3 | rule \ (even X) (odd X) | (odd (s z)) <=> fail. 4 | } 5 | kind nat type. 6 | type s nat -> nat. 7 | type z nat. 8 | 9 | pred even i:nat. 10 | pred odd i:nat. 11 | even z. 12 | 13 | odd (s X) :- even X. 14 | even (s X) :- odd X. 15 | 16 | even (uvar as X) :- declare_constraint (even X) X. 17 | odd (uvar as X) :- declare_constraint (odd X) X. 18 | 19 | main :- 20 | even Z, 21 | declare_constraint true Z, 22 | Z = s W, 23 | not(even W). 24 | 25 | -------------------------------------------------------------------------------- /tests/sources/trace_cut.elpi: -------------------------------------------------------------------------------- 1 | 2 | pred p. 3 | p :- fail. 4 | p :- !, fail. 5 | p. 6 | p :- print 1. 7 | 8 | pred q. 9 | q. 10 | q :- print 2. 11 | 12 | main :- p. 13 | main :- q, !, q => (q :- !) => q. -------------------------------------------------------------------------------- /tests/sources/trace_findall.elpi: -------------------------------------------------------------------------------- 1 | pred p o:int. 2 | p 1. 3 | p 2. 4 | p 3 :- p 2. 5 | 6 | main :- 7 | std.findall (p _) L, print L. -------------------------------------------------------------------------------- /tests/sources/trail.elpi: -------------------------------------------------------------------------------- 1 | % Query: p X Z. 2 | % Expected outcome: X=ok, Z=ok. 3 | 4 | kind tm type. 5 | type a, b tm. 6 | 7 | pred p o:diagnostic, o:diagnostic. 8 | p X Z :- foo Y X, r Y Z. 9 | 10 | pred foo o:tm, o: diagnostic. 11 | foo Y X :- A = ok, q Y, X = A. 12 | 13 | pred q o:tm. 14 | q a. 15 | q b. 16 | 17 | pred r o:tm, o:diagnostic. 18 | r b ok. 19 | 20 | main :- p X Z, X = ok, Z = ok. 21 | -------------------------------------------------------------------------------- /tests/sources/trie.elpi: -------------------------------------------------------------------------------- 1 | pred map2 i:list A, i:list B, i:(A -> B -> C -> prop), o:list C. 2 | map2 [] [_|_] _ _ :- fail. 3 | map2 [_|_] [] _ _ :- fail. 4 | map2 [] [] _ []. 5 | map2 [X|XS] [Y|YS] F [Z|ZS] :- F X Y Z, map2 XS YS F ZS. 6 | 7 | main :- 8 | map2 [1] [1] (x\y\r\r = 1) _, 9 | map2 [] [] (x\y\r\r = 1) _, 10 | map2 [_] [_] (x\y\r\r = 1) _, 11 | 12 | not(map2 [_|_] [_|_] (x\y\r\r = 1) _), % mode 13 | 14 | not(map2 [1] [] (x\y\r\r = 1) _), 15 | not(map2 [] [1] (x\y\r\r = 1) _), 16 | 17 | not(map2 [_] [] (x\y\r\r = 1) _), 18 | not(map2 [] [_] (x\y\r\r = 1) _), 19 | 20 | not(map2 [1|_] [] (x\y\r\r = 1) _), 21 | not(map2 [] [1|_] (x\y\r\r = 1) _), 22 | 23 | not(map2 [_|_] [] (x\y\r\r = 1) _), 24 | not(map2 [] [_|_] (x\y\r\r = 1) _), 25 | 26 | not(map2 [_|_] [_] (x\y\r\r = 1) _), % mode 27 | not(map2 [_] [_|_] (x\y\r\r = 1) _), % mode 28 | 29 | true. 30 | -------------------------------------------------------------------------------- /tests/sources/typeabbrv.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev xx bool. 2 | 3 | namespace foo { 4 | 5 | pred f i:xx. 6 | f _. 7 | 8 | } 9 | 10 | 11 | main :- foo.f tt. -------------------------------------------------------------------------------- /tests/sources/typeabbrv1.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev t1 int. 2 | 3 | pred f i:t1. 4 | f _. 5 | 6 | main :- f 3. -------------------------------------------------------------------------------- /tests/sources/typeabbrv10.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev (bar A) (list A). 2 | typeabbrev (tmp A) (list A). 3 | typeabbrev (foo A) (tmp A). 4 | 5 | pred foo i:int, o:int. 6 | 7 | main :- std.map 3 foo _. -------------------------------------------------------------------------------- /tests/sources/typeabbrv11.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev x int. 2 | 3 | pred f i:x. 4 | f "x". 5 | 6 | main. -------------------------------------------------------------------------------- /tests/sources/typeabbrv12.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev y (list int). 2 | 3 | pred f i:y. 4 | f "x". 5 | 6 | main. -------------------------------------------------------------------------------- /tests/sources/typeabbrv13.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev (dl A) (list A). 2 | 3 | pred p i:dl (dl A). 4 | 5 | main. 6 | 7 | -------------------------------------------------------------------------------- /tests/sources/typeabbrv14.elpi: -------------------------------------------------------------------------------- 1 | kind dl type -> type. 2 | typeabbrev (dl A) (dl A). 3 | 4 | pred p i:dl (dl A). 5 | 6 | main. 7 | 8 | -------------------------------------------------------------------------------- /tests/sources/typeabbrv15.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev x prop. 2 | 3 | type f x. 4 | f. 5 | 6 | main :- f. -------------------------------------------------------------------------------- /tests/sources/typeabbrv2.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev t1 int. 2 | 3 | pred f i:t1. 4 | f _. 5 | 6 | typeabbrev t1 bool. 7 | 8 | main :- f 3. -------------------------------------------------------------------------------- /tests/sources/typeabbrv3.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev (t1 X Y) (pair Y X). 2 | 3 | pred f i:t1 bool int. 4 | f _. 5 | 6 | main :- f (pr 2 tt). -------------------------------------------------------------------------------- /tests/sources/typeabbrv4.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev t1 int. 2 | 3 | pred f i:t1. 4 | f _. 5 | 6 | typeabbrev t1 int. 7 | 8 | main :- f 3. -------------------------------------------------------------------------------- /tests/sources/typeabbrv5.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev x y. 2 | typeabbrev y x. 3 | 4 | pred f i:x. 5 | f _. 6 | 7 | main :- f 0. -------------------------------------------------------------------------------- /tests/sources/typeabbrv6.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev x (option A). 2 | pred f i:x. 3 | f _. 4 | main :- f (some 3). -------------------------------------------------------------------------------- /tests/sources/typeabbrv7.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev xx bool. 2 | 3 | namespace foo { 4 | 5 | pred f i:xx. 6 | f _. 7 | 8 | } 9 | 10 | 11 | main :- foo.f tt. -------------------------------------------------------------------------------- /tests/sources/typeabbrv8.elpi: -------------------------------------------------------------------------------- 1 | { typeabbrev xx bool. } 2 | 3 | type g xx -> xx. 4 | { 5 | pred f i:xx. 6 | f (g _). 7 | 8 | } 9 | 10 | 11 | main :- f (g tt). -------------------------------------------------------------------------------- /tests/sources/typeabbrv9.elpi: -------------------------------------------------------------------------------- 1 | typeabbrev t int. 2 | 3 | namespace xx { 4 | typeabbrev t int. 5 | } 6 | 7 | pred f i:t, i:xx.t. 8 | f 0 0. 9 | 10 | main :- f 0 0. -------------------------------------------------------------------------------- /tests/sources/uminus.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | X is 3 - 2, Y is 3 + -2, 3 | X = 1, Y = 1. -------------------------------------------------------------------------------- /tests/sources/uvar_chr.elpi: -------------------------------------------------------------------------------- 1 | 2 | kind term type. 3 | type app term -> term -> term. 4 | type lam (term -> term) -> term. 5 | 6 | pred unsafe-cast o:A, o:B. 7 | :untyped unsafe-cast X X. 8 | 9 | pred mk-app i:term, i:list term, o:term. 10 | mk-app HD [] HD :- !. 11 | mk-app (uvar as K) [A|Args] R :- !, unsafe-cast K K', mk-app (K' A) Args R. 12 | mk-app HD [X|XS] T :- mk-app (app HD X) XS T. 13 | 14 | pred copy i:term, o:term. 15 | 16 | copy (app A B) (app A1 B1) :- copy A A1, copy B B1. 17 | copy (lam F) (lam F1) :- pi x\ copy x x => copy (F x) (F1 x). 18 | copy (uvar F L as X) T :- var X, !, copy-list L L1, mk-app F L1 T. 19 | copy (uvar C L) (uvar C L1) :- copy-list L L1. 20 | 21 | pred copy-list i:list term, o:list term. 22 | copy-list [] []. 23 | copy-list [X|XS] [Y|YS] :- copy X Y, copy-list XS YS. 24 | 25 | pred meta-copy i:term, o:term. 26 | constraint meta-copy { 27 | rule (meta-copy I O) | (copy I X) <=> (O = X). 28 | } 29 | 30 | main :- In = (lam x\ F x), 31 | copy In T, print T, 32 | declare_constraint (meta-copy In S) [], print S, not(var S). 33 | -------------------------------------------------------------------------------- /tests/sources/var.elpi: -------------------------------------------------------------------------------- 1 | main :- 2 | var X0 _ [], 3 | var X1, 4 | var X2 _ _, 5 | (pi x y\ (var (X3 x y) X3 [x,y])), 6 | (pi x y\ (var (X9 x y) X9 (X10 x y))), 7 | (pi x y\ sigma X5\ (var X5 X4 [x,y]), 8 | print X0 "," X1 "," X2 "," X3 "," X4 "," X5). -------------------------------------------------------------------------------- /tests/sources/variadic_declare_constraints.elpi: -------------------------------------------------------------------------------- 1 | kind tm type. 2 | type foo tm -> (tm -> tm) -> prop. 3 | 4 | main :- 5 | declare_constraint (foo X Y) X [Y, Z]. -------------------------------------------------------------------------------- /tests/suite/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name test_suite) 3 | (libraries str unix fileutils) 4 | (library_flags -linkall) 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /tests/suite/performance_HO.ml: -------------------------------------------------------------------------------- 1 | (* elpi: embedded lambda prolog interpreter *) 2 | (* license: GNU Lesser General Public License Version 2.1 or later *) 3 | (* ------------------------------------------------------------------------- *) 4 | open Suite 5 | 6 | let declare = Test.declare 7 | ~category:(Filename.(chop_extension (basename __FILE__))) 8 | 9 | 10 | let () = declare "grundlagen" 11 | ~source_elpi:"helena_elpi/ld3_engine.elpi" 12 | ~description:"type checker for λδ" 13 | () 14 | 15 | let () = declare "lyp" 16 | ~source_elpi:"lyp/lyp_engine.elpi" 17 | ~description:"type checker for λΥP" 18 | () 19 | 20 | let () = declare "cbv" 21 | ~source_elpi:"reduce_cbv.elpi" 22 | ~source_teyjus:"reduce_cbv.mod" 23 | ~description:"reduction" 24 | () 25 | let () = declare "cbn" 26 | ~source_elpi:"reduce_cbn.elpi" 27 | ~source_teyjus:"reduce_cbn.mod" 28 | ~description:"reduction" 29 | () 30 | 31 | let () = declare "lambda3" 32 | ~source_elpi:"lambda3.elpi" 33 | ~source_teyjus:"lambda3.mod" 34 | ~description:"moving under lambdas" 35 | () 36 | -------------------------------------------------------------------------------- /tests/test.dummy.ml: -------------------------------------------------------------------------------- 1 | let () = 2 | Printf.eprintf "test not available, some build dependencies are missing\n"; 3 | exit 1 -------------------------------------------------------------------------------- /trace/ppx/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name trace_ppx) 3 | (public_name elpi.trace.ppx) 4 | (libraries ppxlib) 5 | (preprocess (pps ppxlib.metaquot)) 6 | (kind ppx_rewriter) 7 | (ppx_runtime_libraries elpi.trace.runtime) 8 | (modules trace_ppx) 9 | (optional) 10 | ) 11 | -------------------------------------------------------------------------------- /trace/runtime/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name trace_ppx_runtime) 3 | (public_name elpi.trace.runtime) 4 | (libraries re) 5 | (modules runtime) 6 | ) --------------------------------------------------------------------------------