# Print a list of tuples

**URL:** https://discuss.ocaml.org/t/print-a-list-of-tuples/12502
**Category:** Learning
**Tags:** pretty-printing, list, sexp
**Created:** [June 29, 2023, 3:52am UTC](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502 "2023-06-29T03:52:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![vivanov](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/vivanov/32/4455_2.png) [@vivanov](https://discuss.ocaml.org/u/vivanov)
#### Post date: [June 29, 2023, 3:52am UTC](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502/1 "2023-06-29T03:52:18Z")

</div>

Hey, I am looking for a way to print structures for debugging purposes, and for other purposes. For example, I have a function that produces a list of tuples:

```auto
 List.mapi (
        fun i (name, address) -> 
          Printf.sprintf "Level: %d, name: %d, address: %d" i name address
      ) l
      |> String.concat " " 

```

Is there a simpler way to print it, maybe using `[@@deriving sexp]` I found in Base?

---

<div class="post-metadata">

### Author: ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)
#### Post date: [June 29, 2023, 5:24am UTC](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502/2 "2023-06-29T05:24:05Z")

</div>

If you don’t mind using PPX, you can use the `[@@deriving show]` plugin, see [GitHub - ocaml-ppx/ppx\_deriving: Type-driven code generation for OCaml](https://github.com/ocaml-ppx/ppx_deriving#plugin-show).

Cheers,  
Nicolas

---

<div class="post-metadata">

### Author: ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)
#### Post date: [June 29, 2023, 1:14pm UTC](https://discuss.ocaml.org/t/print-a-list-of-tuples/12502/3 "2023-06-29T13:14:22Z")

</div>

You can also use `Fmt` combinators, something like

```ocaml
let pp_tupl = Fmt.Dump.(list (pair Fmt.int Fmt.int)) in
Format.asprintf "%a" pp_tupl my_value

```
