-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from mbarbin/runtime-info
Register custom trait names instead of extensible variant names
- Loading branch information
Showing
22 changed files
with
164 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
open! Import | ||
|
||
type t = (int, string) Hashtbl.t | ||
|
||
let create () = Hashtbl.create 16 | ||
let default = create () | ||
let set_name t trait ~name = Hashtbl.add t ~key:(Trait0.uid trait) ~data:name | ||
let get_name t trait = Hashtbl.find_opt t (Trait0.uid trait) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(** A mutable data structure to attach names to trait uids. | ||
This is meant to be used in tests only to make the information attached to | ||
trait more meaningful. *) | ||
|
||
(** A mutable data structure to store the names. *) | ||
type t | ||
|
||
val create : unit -> t | ||
|
||
(** [default] is the one and only hashtbl used by the provider library. This is | ||
where info is stored when [Provider.Trait.Info.register_name] is called. *) | ||
val default : t | ||
|
||
val set_name : t -> _ Trait0.t -> name:string -> unit | ||
val get_name : t -> _ Trait0.t -> string option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
type (_, _, _) Provider.Trait.t += | ||
| T : ('t, (module T with type t = 't), [> `T ]) Provider.Trait.t | ||
|
||
let%expect_test "info" = | ||
(* By default, id are not shown, and trait do not have names. *) | ||
let print_info () = print_s [%sexp (Provider.Trait.info T : Provider.Trait.Info.t)] in | ||
[%expect {||}]; | ||
(* It is possible to show the id with custom functions. *) | ||
Ref.set_temporarily | ||
Provider.Trait.Info.sexp_of_id | ||
(fun (_ : int) -> Sexp.Atom "#customized-id") | ||
~f:(fun () -> print_info ()); | ||
[%expect {| | ||
((id #customized-id) | ||
(name <none>)) | ||
|}]; | ||
(* It is also possible to register a name for a trait. *) | ||
let () = Provider.Trait.Info.register_name T ~name:"Hello Name!" in | ||
print_info (); | ||
[%expect {| | ||
((id #id) | ||
(name "Hello Name!")) | ||
|}]; | ||
(* The name can be changed. Whether this is desirable is up to the user. *) | ||
let () = Provider.Trait.Info.register_name T ~name:"Goodbye Name!" in | ||
print_info (); | ||
[%expect {| | ||
((id #id) | ||
(name "Goodbye Name!")) | ||
|}]; | ||
() | ||
;; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.