Skip to content

Commit

Permalink
curry api
Browse files Browse the repository at this point in the history
resolve RedPRL#131

Signed-off-by: Lîm Tsú-thuàn <[email protected]>
  • Loading branch information
dannypsnl committed Jan 10, 2025
1 parent 3ae2637 commit 8bec9b4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand All @@ -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) }
Expand Down
8 changes: 4 additions & 4 deletions src/ScopeSigs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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].
Expand All @@ -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.
Expand All @@ -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].
Expand Down
4 changes: 2 additions & 2 deletions test/EasyExample.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
6 changes: 3 additions & 3 deletions test/Example.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down

0 comments on commit 8bec9b4

Please sign in to comment.