# Printf.printf "uri: %a" Uri.pp Uri.empty

**URL:** <https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810>\
**Category:** Learning\
**Tags:** printf\
**Created:** [March 28, 2023, 11:11am UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810 "2023-03-28T11:11:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mro/32/2496_2.png) [@mro](https://discuss.ocaml.org/u/mro)\
**Post date:** [March 28, 2023, 11:11am UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810/1 "2023-03-28T11:11:42Z")

</div>

gives me

```auto
Error: This expression has type Format.formatter -> Uri.t -> unit
       but an expression was expected of type out_channel -> 'a -> unit
       Type Format.formatter is not compatible with type out_channel

```

how can I use %a with printf then? I know [OCaml library : Printf](https://v2.ocaml.org/api/Printf.html) but just can’t make sense of it.

---

<div class="post-metadata">

**Author:** ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)\
**Post date:** [March 28, 2023, 11:16am UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810/2 "2023-03-28T11:16:55Z")

</div>

`Uri.pp` is designed to work with `Format.printf` (works with formatters), not `Printf.printf` (works with channels).

---

<div class="post-metadata">

**Author:** ![mro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mro/32/2496_2.png) [@mro](https://discuss.ocaml.org/u/mro)\
**Post date:** [March 28, 2023, 12:52pm UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810/3 "2023-03-28T12:52:43Z")

</div>

So I guess I will mostly phase out `Printf` in favour of `Format`.

Edit: uh, I guess I will keep it for everything machine readable.

---

<div class="post-metadata">

**Author:** ![mro](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mro/32/2496_2.png) [@mro](https://discuss.ocaml.org/u/mro)\
**Post date:** [April 1, 2023, 3:27pm UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810/4 "2023-04-01T15:27:30Z")

</div>

oh, please llow me one more question, shouldn’t

`Format.sprintf "%a" Uri.pp Uri.empty`

return an empty string? Instead I get a type error I can’t make sense of.

---

<div class="post-metadata">

**Author:** ![K\_N](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/k_n/32/2793_2.png) [@K\_N](https://discuss.ocaml.org/u/K_N)\
**Post date:** [April 1, 2023, 3:32pm UTC](https://discuss.ocaml.org/t/printf-printf-uri-a-uri-pp-uri-empty/11810/5 "2023-04-01T15:32:13Z")

</div>

You should try with `Format.asprintf`.
