# Problems after switching to Base

**URL:** <https://discuss.ocaml.org/t/problems-after-switching-to-base/1148>\
**Category:** Learning\
**Created:** [November 18, 2017, 5:29pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148 "2017-11-18T17:29:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinklepsch](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/martinklepsch/32/624_2.png) [@martinklepsch](https://discuss.ocaml.org/u/martinklepsch)\
**Post date:** [November 18, 2017, 5:29pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/1 "2017-11-18T17:29:26Z")

</div>

Complete newbie here, I just added Base to my project but now using `printf` just stopped working:

```auto
(executable
 ((name hello_print)
  (libraries (base))))

```

```ocaml
open Base ;;

let pr_str_list xs =
  List.iter (Printf.printf "%s, ") xs ;;

```

Reading the [Base documentation](https://ocaml.janestreet.com/ocaml-core/v0.9/doc/base/Base/index.html) it seems that `Printf` in Base is aliased to `Caml.Printf` or something?

How do I need to rewrite my program above so that it works with Base?

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [November 18, 2017, 5:44pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/2 "2017-11-18T17:44:37Z")

</div>

This is because Base doesn’t include IO. You need Stdio for that, at which point, this works.

```ocaml
open Base
open Stdio

let pr_str_list xs =
  List.iter ~f:(printf "%s, ") xs

```

---

<div class="post-metadata">

**Author:** ![martinklepsch](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/martinklepsch/32/624_2.png) [@martinklepsch](https://discuss.ocaml.org/u/martinklepsch)\
**Post date:** [November 18, 2017, 6:01pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/3 "2017-11-18T18:01:01Z")

</div>

Thanks for the quick response @Yaron_Minsky, that solves the issue. 🙂

One more thing:

Why does this work

```ocaml
open Base
open Stdio;;

print_endline "Parsing Transactions..."

```

But this doesn’t?

```ocaml
open Base
open Stdio

print_endline "Parsing Transactions..."

```

According to [this Reddit thread](https://www.reddit.com/r/ocaml/comments/2fv1ba/coming_from_other_languages_whats_the_difference/) double semicolons shouldn’t be needed outside a REPL?

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [November 18, 2017, 6:30pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/4 "2017-11-18T18:30:08Z")

</div>

You don’t need double-semis if you use a top-level binding.

```ocaml
open Base
open Stdio

let () = print_endline "Parsing Transactions..."

```

---

<div class="post-metadata">

**Author:** ![anon72795300](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@anon72795300](https://discuss.ocaml.org/u/anon72795300)\
**Post date:** [November 18, 2017, 6:42pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/5 "2017-11-18T18:42:35Z")

</div>

It doesn’t seem like you want to mix modules here, but if you did you could do either:

```auto
let module S = Some_module in

S.print_endline "..." ...; (* Module's print_endline *)
print_endline "..." .. (* Std print_endline *)

```

or

```auto
lets special_print_endline = Some_module.print_endline in

special_print_endline "" ...;
print_endline "" ...

```

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [November 21, 2017, 4:50am UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/6 "2017-11-21T04:50:08Z")

</div>

Is this a temporary issue, or a design policy for `Base` as opposed to `Core`? Will `Base.Printf` provide more functions, such as `printf`, in the future? Or will some of those functions be split out of `Core.Printf`? Just curiosity.

---

<div class="post-metadata">

**Author:** ![Yaron\_Minsky](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yaron_minsky/32/11_2.png) [@Yaron\_Minsky](https://discuss.ocaml.org/u/Yaron_Minsky)\
**Post date:** [November 21, 2017, 11:22am UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/7 "2017-11-21T11:22:12Z")

</div>

It’s a design policy of Base, and I could imagine doing the same eventually  
for Core and Core\_kernel. Separating out the IO into a separate library is  
I think sensible, and it would be better if Core had always done that. This  
is why Async has to shadow a bunch of things in Core, when really it would  
be better if one had to open something separate to get IO.

For what it’s worth, the out-channel writing printf is now in Out\_channel,  
which is a sensible place for it anyway, as well as in the toplevel of  
Stdio.

y

---

<div class="post-metadata">

**Author:** ![mars0i](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mars0i/32/1058_2.png) [@mars0i](https://discuss.ocaml.org/u/mars0i)\
**Post date:** [November 21, 2017, 2:12pm UTC](https://discuss.ocaml.org/t/problems-after-switching-to-base/1148/8 "2017-11-21T14:12:17Z")

</div>

Thanks @Yaron_Minsky. That makes sense. It fits with the overall design philosophy of Core, I think.
