Adds an example (OCaml Examples Project)#163
Adds an example (OCaml Examples Project)#163johnwhitington wants to merge 2 commits intomirage:mainfrom
Conversation
| let n = input fh buf 0 1024 in | ||
| context := Digestif.SHA256.feed_bytes !context ~off:0 ~len:n buf; | ||
| if n = 0 then fin := true | ||
| done; |
There was a problem hiding this comment.
It will be nice to show a comparative example which does not use a reference but proposes a more functional way to digest something:
let rec go ctx =
let len = input fh buf 0 1024 in
if len = 0 then Digestif.SHA256.get ctx
else go (Digestif.SHA256.feed_bytes ctx ~off:0 ~len buf) in
go Digestif.SHA256.empty| fe6e6639a817c23857b507e2d833ec776f23f327 | ||
| ``` | ||
|
|
||
| A further example is given in the examples directory. |
There was a problem hiding this comment.
The example above is like what you propose. It will be nice to show up something more complex like: digest something in parallel (OCaml 4 & OCaml 5) with digest_bigstring. Digestif has a nice property to release the GC when it's about digest a bigstring.
|
Another question highlighted by the Thanks for your contribution, I don't have too much time these weeks to really help you but I can try to help you to complete the documentation and examples next month. |
Hello!
This pull request adds some examples to Digestif. This is part of a pilot programme funded by the OCaml Software Foundation.
Many OCaml libraries have no examples, or perfunctory examples only. This makes it difficult to get started with a library, particularly if it has an elaborate interface. A working example, no matter how small, can help a newcomer get started quickly. One day, it would be nice to have an example for every Opam package.
For now, examples begin in the OCaml Nursery, here: https://github.com/johnwhitington/ocaml-nursery (you can read in the README there about the principles behind these examples.) Then, if package authors agree, they are promoted to upstream source. The hope is that this will mean they are more likely to be kept up to date with the library.
The examples are included in a separate directory, within a separate Dune workspace. And so they are intended to be used after installation of the library.
As well as considering accepting this pull request, please give any comments you have on this programme.