diff --git a/README.md b/README.md index 84104c4..4f2eeae 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_713 TILs and counting..._ +_714 TILs and counting..._ --- @@ -512,6 +512,7 @@ _713 TILs and counting..._ - [Break Out Of A While Loop](reason/break-out-of-a-while-loop.md) - [Compile Reason To Native With Dune](reason/compile-reason-to-native-with-dune.md) +- [Compile Reason With An OCaml Package Using Dune](reason/compile-reason-with-an-ocaml-package-using-dune.md) - [Create A Stream From An Array](reason/create-a-stream-from-an-array.md) - [Data Structures With Self-Referential Types](reason/data-structures-with-self-referential-types.md) - [Defining Variants With Constructor Arguments](reason/defining-variants-with-constructor-arguments.md) diff --git a/reason/compile-reason-with-an-ocaml-package-using-dune.md b/reason/compile-reason-with-an-ocaml-package-using-dune.md new file mode 100644 index 0000000..627400b --- /dev/null +++ b/reason/compile-reason-with-an-ocaml-package-using-dune.md @@ -0,0 +1,35 @@ +# Compile Reason With An OCaml Package Using Dune + +In [Compile Reason To Native With +Dune](reason/compile-reason-to-native-with-dune.md), I showed how to compile +a basic ReasonML file as a native executable using Dune. + +Any non-trivial program will likely involve pulling in an OCaml dependency. +For example, you may want to pull in [Lwt](https://github.com/ocsigen/lwt). +Assuming this package is available, whether you've manually downloaded it +via [opam](https://opam.ocaml.org/) or used something like +[esy](https://github.com/esy/esy), you'll want to let Dune know that Lwt is +an available library. + +```lisp +;; dune +(executable + (name hello_reason) + (libraries lwt lwt.unix)) +``` + +The modules in the Lwt package will now be globally available to your +Reason code. + +```reason +let () = { + Lwt_main.run( + Lwt_io.printf("Hello, Reason!\n") + ); +}; +``` + +When Dune builds your code, it will include and compile Lwt. + +See a [full example +here](https://github.com/jbranchaud/esy-reasonml-lwt-example).