# How to compile Let\_syntax of Base?

**URL:** <https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890>\
**Category:** Learning\
**Tags:** base\
**Created:** [April 22, 2018, 3:02am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890 "2018-04-22T03:02:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taki](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/taki/32/718_2.png) [@Taki](https://discuss.ocaml.org/u/Taki)\
**Post date:** [April 22, 2018, 3:02am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/1 "2018-04-22T03:02:46Z")

</div>

I’m reading [RWO v2](https://dev.realworldocaml.org/error-handling.html) and try to write my own demo as:

```ocaml
open Base
open Stdio

let f1 n =
  if n < 10 then None else Some n

let f2 n =
  if n > 15 then None else Some n

let combines n =
  let open Option.Let_syntax in
  let%bind r1 = f1 n in
  let%bind r2 = f2 n in
  Some r2

let _ = 
  match combines 13 with
  | Some x -> print_int x
  | None -> print_endline "nothing"

```

The jbuild file:

```auto
(executables
 ((names (t))
  (libraries (base stdio))
  ))

```

But there’s an error:

```bash
$ jbuilder build t.exe
File "t.ml", line 12, characters 6-10:
Error: Uninterpreted extension 'bind'.

```

---

<div class="post-metadata">

**Author:** ![bobbypriambodo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bobbypriambodo/32/179_2.png) [@bobbypriambodo](https://discuss.ocaml.org/u/bobbypriambodo)\
**Post date:** [April 22, 2018, 3:46am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/2 "2018-04-22T03:46:40Z")

</div>

AFAIK you should have [ppx\_let](https://github.com/janestreet/ppx_let) installed (via `opam install ppx_let` if haven’t transitively depended), and add the `preprocess` stanza on your `jbuild` file, as such:

```auto
(executables
 ((names (t))
  (libraries (base stdio))
  (preprocess (pps (ppx_let)))
  ))

```

---

<div class="post-metadata">

**Author:** ![bcc32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bcc32/32/203_2.png) [@bcc32](https://discuss.ocaml.org/u/bcc32)\
**Post date:** [April 22, 2018, 9:44am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/3 "2018-04-22T09:44:13Z")

</div>

In general, the ppx syntax extensions used in RWO are all transitively included by `ppx_jane`, so using that in your jbuild file should fix it for `[@@deriving sexp]`, `[%compare: int list]`, etc.

---

<div class="post-metadata">

**Author:** ![flazz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/flazz/32/2433_2.png) [@flazz](https://discuss.ocaml.org/u/flazz)\
**Post date:** [October 12, 2020, 6:43am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/4 "2020-10-12T06:43:53Z")

</div>

I seem to have almost the exact same issue but updated for 2020

some code:

```
let _ =
  let open Option.Let_syntax in
  let%bind x = Some(1) in
  x

```

the dune:

```
(library
 (name sre)
 (inline_tests)
 (preprocess
  (pps ppx_let ppx_inline_test))
 (libraries str))

```

the dune build output:

```
File "lib/nth.ml", line 2, characters 11-28:
2 | let open Option.Let_syntax in
               ^^^^^^^^^^^^^^^^^
Error: Unbound module Option.Let_syntax
```

---

<div class="post-metadata">

**Author:** ![mseri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mseri/32/91_2.png) [@mseri](https://discuss.ocaml.org/u/mseri)\
**Post date:** [October 12, 2020, 6:53am UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/5 "2020-10-12T06:53:11Z")

</div>

Base is not listed in the dune file. Try replacing `(libraries str)` with `(libraries base str)`

---

<div class="post-metadata">

**Author:** ![flazz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/flazz/32/2433_2.png) [@flazz](https://discuss.ocaml.org/u/flazz)\
**Post date:** [October 12, 2020, 2:26pm UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/6 "2020-10-12T14:26:18Z")

</div>

Adding `base` didn’t work, same error. Could something be missing from opam?

---

<div class="post-metadata">

**Author:** ![Levi\_Roth](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/levi_roth/32/2268_2.png) [@Levi\_Roth](https://discuss.ocaml.org/u/Levi_Roth)\
**Post date:** [October 12, 2020, 2:53pm UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/7 "2020-10-12T14:53:06Z")

</div>

You’ll also probably need to `open Base` to the top of the .ml file so that you’ll be using the Base version of the option module.

---

<div class="post-metadata">

**Author:** ![flazz](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/flazz/32/2433_2.png) [@flazz](https://discuss.ocaml.org/u/flazz)\
**Post date:** [October 12, 2020, 3:47pm UTC](https://discuss.ocaml.org/t/how-to-compile-let-syntax-of-base/1890/8 "2020-10-12T15:47:12Z")

</div>

That was it, thanks @mseri & @Levi_Roth !
