From 8bec9b4735e6cb2e54d5561821df43a06df7a728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AEm=20Ts=C3=BA-thu=C3=A0n?= Date: Fri, 10 Jan 2025 14:51:02 +0800 Subject: [PATCH 1/2] curry api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #131 Signed-off-by: Lîm Tsú-thuàn --- src/Scope.ml | 8 ++++---- src/ScopeSigs.ml | 8 ++++---- test/EasyExample.ml | 4 ++-- test/Example.ml | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Scope.ml b/src/Scope.ml index 49851e21..262baab7 100644 --- a/src/Scope.ml +++ b/src/Scope.ml @@ -57,12 +57,12 @@ struct Mod.union ?context:context_export ~prefix:(export_prefix()) s.export @@ Mod.modify ?context:context_modifier m s.visible } - let include_singleton ?context_visible ?context_export (path, x) = + let include_singleton ?context_visible ?context_export path x = M.exclusively @@ fun () -> S.modify @@ fun s -> { visible = Mod.union_singleton ?context:context_visible s.visible (path, x); export = Mod.union_singleton ?context:context_export ~prefix:(export_prefix()) s.export (path, x) } - let import_singleton ?context_visible (path, x) = + let import_singleton ?context_visible path x = M.exclusively @@ fun () -> S.modify @@ fun s -> { s with visible = Mod.union_singleton ?context:context_visible s.visible (path, x) } @@ -72,10 +72,10 @@ struct { visible = Mod.union_subtree ?context:context_visible s.visible (path, ns); export = Mod.union_subtree ?context:context_export ~prefix:(export_prefix()) s.export (path, ns) } - let include_subtree ?context_modifier ?context_visible ?context_export ?(modifier=Language.id) (path, ns) = + let include_subtree ?context_modifier ?context_visible ?context_export ?(modifier=Language.id) path ns = M.exclusively @@ fun () -> unsafe_include_subtree ~context_modifier ~context_visible ~context_export ~modifier (path, ns) - let import_subtree ?context_modifier ?context_visible ?(modifier=Language.id) (path, ns) = + let import_subtree ?context_modifier ?context_visible ?(modifier=Language.id) path ns = M.exclusively @@ fun () -> S.modify @@ fun s -> let ns = Mod.modify ?context:context_modifier ~prefix:Emp modifier ns in { s with visible = Mod.union_subtree ?context:context_visible s.visible (path, ns) } diff --git a/src/ScopeSigs.ml b/src/ScopeSigs.ml index fc8b5d70..4e8543d4 100644 --- a/src/ScopeSigs.ml +++ b/src/ScopeSigs.ml @@ -42,7 +42,7 @@ sig Inclusion affects both visible and export namespaces, just like [include] in OCaml. *) - val include_singleton : ?context_visible:context -> ?context_export:context -> Trie.path * (data * tag) -> unit + val include_singleton : ?context_visible:context -> ?context_export:context -> Trie.path -> (data * tag) -> unit (** [include_singleton (p, x)] adds a new binding to both the visible and export namespaces, where the binding is associating the data [x] to the path [p]. Conflicting names during the final merge will trigger the effect [shadow]. [include_singleton (p, x)] is equivalent to [include_subtree Trie.(singleton (p, x))], but potentially more efficient. @@ -52,7 +52,7 @@ sig @param context_visible The context of modifier effects when merging the subtree into the visible namespace. @param context_export The context of modifier effects when merging the subtree into the export namespace. *) - val include_subtree : ?context_modifier:context -> ?context_visible:context -> ?context_export:context -> ?modifier:hook Language.t -> Trie.path * (data, tag) Trie.t -> unit + val include_subtree : ?context_modifier:context -> ?context_visible:context -> ?context_export:context -> ?modifier:hook Language.t -> Trie.path -> (data, tag) Trie.t -> unit (** [include_subtree (p, ns)] merges the namespace [ns] prefixed with [p] into both the visible and export namespaces. Conflicting names during the final merge will trigger the effect [shadow]. @@ -68,7 +68,7 @@ sig Importing affects only the visible namespace, just like [open] in OCaml. *) - val import_singleton : ?context_visible:context -> Trie.path * (data * tag) -> unit + val import_singleton : ?context_visible:context -> Trie.path -> (data * tag) -> unit (** [import_singleton (p, x)] adds a new binding to the visible namespace (while keeping the export namespace intact), where the binding is associating the data [x] to the path [p]. Conflicting names during the final merge will trigger the effect [shadow]. [import_singleton (p, x)] is equivalent to [import_subtree Trie.(singleton (p, x))], but potentially more efficient. @@ -83,7 +83,7 @@ sig @param context_visible The context of modifier effects when merging the subtree into the visible namespace. @since 5.0.0 *) - val import_subtree : ?context_modifier:context -> ?context_visible:context -> ?modifier:hook Language.t -> Trie.path * (data, tag) Trie.t -> unit + val import_subtree : ?context_modifier:context -> ?context_visible:context -> ?modifier:hook Language.t -> Trie.path -> (data, tag) Trie.t -> unit (** [import_subtree (p, ns)] merges the namespace [ns] prefixed with [p] into the visible namespace (while keeping the export namespace intact). Conflicting names during the final merge will trigger the effect [shadow]. diff --git a/test/EasyExample.ml b/test/EasyExample.ml index 41fb38f4..d147d1fe 100644 --- a/test/EasyExample.ml +++ b/test/EasyExample.ml @@ -31,10 +31,10 @@ let pp_path fmt = let rec interpret_decl : decl -> unit = function | Decl (p, x) -> - S.include_singleton (p, (x, ())) + S.include_singleton p (x, ()) | Import (t, m) -> let t = Trie.retag () t in - S.import_subtree ~modifier:m ([], t) + S.import_subtree ~modifier:m [] t | Export p -> S.export_visible (Language.only p) | Section (p, sec) -> diff --git a/test/Example.ml b/test/Example.ml index 8d58c4cc..0b90bb2c 100644 --- a/test/Example.ml +++ b/test/Example.ml @@ -80,13 +80,13 @@ end let rec interpret_decl : decl -> unit = function | Decl (p, x) -> - S.include_singleton ~context_visible:`Visible ~context_export:`Export (p, (x, `Local)) + S.include_singleton ~context_visible:`Visible ~context_export:`Export p (x, `Local) | ShadowingDecl (p, x) -> S.try_with ~shadow:S.Silence.shadow @@ fun () -> - S.include_singleton (p, (x, `Local)) + S.include_singleton p (x, `Local) | Import (t, m) -> let t = Trie.Untagged.tag `Imported t in - S.import_subtree ~modifier:m ([], t) + S.import_subtree ~modifier:m [] t | PrintVisible -> S.modify_visible (Language.hook Print) | Export p -> From 57a4cc8aa21ad0ad13d5012b2abe52a9babe19ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=AEm=20Ts=C3=BA-thu=C3=A0n?= Date: Fri, 10 Jan 2025 18:56:44 +0800 Subject: [PATCH 2/2] formatting Co-authored-by: favonia --- src/ScopeSigs.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ScopeSigs.ml b/src/ScopeSigs.ml index 4e8543d4..beacdaa3 100644 --- a/src/ScopeSigs.ml +++ b/src/ScopeSigs.ml @@ -42,7 +42,7 @@ sig Inclusion affects both visible and export namespaces, just like [include] in OCaml. *) - val include_singleton : ?context_visible:context -> ?context_export:context -> Trie.path -> (data * tag) -> unit + val include_singleton : ?context_visible:context -> ?context_export:context -> Trie.path -> (data * tag) -> unit (** [include_singleton (p, x)] adds a new binding to both the visible and export namespaces, where the binding is associating the data [x] to the path [p]. Conflicting names during the final merge will trigger the effect [shadow]. [include_singleton (p, x)] is equivalent to [include_subtree Trie.(singleton (p, x))], but potentially more efficient.