Skip to content

Commit

Permalink
Add a hello_world reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbin committed Aug 5, 2024
1 parent f33a1a0 commit ba4d5e8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions doc/docs/reference/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(mdx
(deps
(package provider)
(glob_files *.txt))
(preludes prelude.txt))
35 changes: 35 additions & 0 deletions doc/docs/reference/hello_world.md
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 = ()
```
2 changes: 2 additions & 0 deletions doc/docs/reference/prelude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#require "unix" ;;
#require "provider" ;;
1 change: 1 addition & 0 deletions doc/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const sidebars: SidebarsConfig = {
items: [
{ type: 'doc', id: 'reference/odoc', label: 'OCaml Packages' },
{ type: 'doc', id: 'reference/glossary', label: 'Glossary' },
{ type: 'doc', id: 'reference/hello_world', label: 'Hello World' },
],
},
],
Expand Down

0 comments on commit ba4d5e8

Please sign in to comment.