-
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.
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(mdx | ||
(deps | ||
(package provider) | ||
(glob_files *.txt)) | ||
(preludes prelude.txt)) |
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,35 @@ | ||
# Hello World | ||
|
||
Below is a minimalist program that uses the Provider library (cheat sheet). | ||
|
||
```ocaml | ||
module type S = sig | ||
type t | ||
val show : t -> string | ||
end | ||
type show = [ `Show ] | ||
type (_, _, _) Provider.Trait.t += | ||
Show : ('t, (module S with type t = 't), [> show ]) Provider.Trait.t | ||
let print (Provider.T { t; interface }) = | ||
let module M = (val Provider.Interface.lookup interface ~trait:Show) in | ||
print_endline (M.show t) | ||
let string_provider t = | ||
let interface = | ||
Provider.Interface.make | ||
[ Provider.Trait.implement Show | ||
~impl:(module struct type t = string let show = Fun.id end) | ||
] | ||
in | ||
Provider.T { t; interface } | ||
``` | ||
|
||
```ocaml | ||
# print (string_provider "Hello World") | ||
Hello World | ||
- : unit = () | ||
``` |
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,2 @@ | ||
#require "unix" ;; | ||
#require "provider" ;; |
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