From 74be31dfce32583db0fa5272f933f7f2670da51e Mon Sep 17 00:00:00 2001 From: Kakadu Date: Fri, 25 Mar 2022 22:20:24 +0300 Subject: [PATCH] An example about partial application of closures Signed-off-by: Kakadu --- examples/closure/dune | 32 ++++++++- examples/closure/partial.ml | 21 ++++++ examples/closure/partial.svg | 122 +++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 examples/closure/partial.ml create mode 100644 examples/closure/partial.svg diff --git a/examples/closure/dune b/examples/closure/dune index c4702ab..09bc43e 100644 --- a/examples/closure/dune +++ b/examples/closure/dune @@ -1,4 +1,3 @@ - (executable (name example) (modules example) @@ -57,3 +56,34 @@ (name examples) (deps doc.svg) ) + +(executable + (name partial) + (modules partial) + (libraries memgraph)) + +(rule + (target partial.gv) + (package memgraph) + (action + (with-outputs-to + %{target} + (with-accepted-exit-codes + 0 + (run ./partial.exe))))) + +(rule + (target partial.svg) + (deps partial.gv) + (package memgraph) + (mode promote) + (action + (with-outputs-to + %{target} + (with-accepted-exit-codes + 0 + (run dot -Tsvg -o %{target} %{deps}))))) + +(alias + (name examples) + (deps partial.svg)) diff --git a/examples/closure/partial.ml b/examples/closure/partial.ml new file mode 100644 index 0000000..8aabd62 --- /dev/null +++ b/examples/closure/partial.ml @@ -0,0 +1,21 @@ + +let test () = + let f x y z = x + y + z in + f + +let test2 () = + let f x y z = x + y + z in + let g = f 11 in + f, g + +let () = + let _f1 = test () in + let f2, _g2 = test2 () in + Memgraph.Repr.(context (fun ctx -> + Memgraph.Dot.print_list Format.std_formatter [ + (* "f1", ctx.mk f1; *) + (* "f1 18", ctx.mk (f1 18); *) + "f2", ctx.mk f2; + (* "g2", ctx.mk g2; *) + "f2 18", ctx.mk (f2 18); + ])) diff --git a/examples/closure/partial.svg b/examples/closure/partial.svg new file mode 100644 index 0000000..faefafe --- /dev/null +++ b/examples/closure/partial.svg @@ -0,0 +1,122 @@ + + + + + + +g + + +entry_1 + +val : f2 18 + +. + + + +p1 + +Tag : 247 + +. + +72057594037927939 + +. + +18 + +. + + + +entry_1->p1:head + + + + + +entry_0 + +val : f2 + +. + + + +p2 + +Tag : 247 + +. + +108086391056891907 + +. + + + +entry_0->p2:head + + + + + +e94514915463424 + +Out of heap : 0x55f5f7f65100 + + + +p2:f0->e94514915463424:head + + + + + +e94514915464768 + +Out of heap : 0x55f5f7f65640 + + + +p2:f2->e94514915464768:head + + + + + +p1:f4->p2:head + + + + + +e94514915463552 + +Out of heap : 0x55f5f7f65180 + + + +p1:f0->e94514915463552:head + + + + + +e94514915463520 + +Out of heap : 0x55f5f7f65160 + + + +p1:f2->e94514915463520:head + + + + +