# \#toplevel

**URL:** https://discuss.ocaml.org/tag/toplevel/238.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [Get the currently accessible paths (Load\_path.get\_path\_list) from a toplevel plugin](https://discuss.ocaml.org/t/get-the-currently-accessible-paths-load-path-get-path-list-from-a-toplevel-plugin/16522)

<div class="topic-metadata">

**Author:** [@kit-ty-kate](https://discuss.ocaml.org/u/kit-ty-kate)\
**Replies:** 3\
**Last updated:** [April 19, 2025, 7:08am UTC](https://discuss.ocaml.org/t/get-the-currently-accessible-paths-load-path-get-path-list-from-a-toplevel-plugin/16522 "2025-04-19T07:08:58Z")

</div>

Hi, I’m trying to write a patch for down and i need the list of currently accessible paths (i.e. the list of directories which the compiler uses to discover identifiers, added using #directory and the like). However Lo…

---

## [2 lines to get an OCaml toplevel REPL](https://discuss.ocaml.org/t/2-lines-to-get-an-ocaml-toplevel-repl/15880)

<div class="topic-metadata">

**Author:** [@jbeckford](https://discuss.ocaml.org/u/jbeckford)\
**Replies:** 0\
**Last updated:** [January 2, 2025, 4:23am UTC](https://discuss.ocaml.org/t/2-lines-to-get-an-ocaml-toplevel-repl/15880 "2025-01-02T04:23:30Z")

</div>

I have a Down¹-based REPL for debugging DkCoder scripts. It may be useful to others who want to quickly try out OCaml with a reasonable set of bundled libraries without a prior installation. In PowerShell on Windows, or…

---

## [Val top\_level : string -\> string](https://discuss.ocaml.org/t/val-top-level-string-string/15547)

<div class="topic-metadata">

**Author:** [@Jon\_Harrop](https://discuss.ocaml.org/u/Jon_Harrop)\
**Replies:** 1\
**Last updated:** [November 3, 2024, 9:08pm UTC](https://discuss.ocaml.org/t/val-top-level-string-string/15547 "2024-11-03T21:08:43Z")

</div>

I’d like a function that takes OCaml code like 2+3 in the form of a string, runs the code through a fresh top-level and returns the string that the top-level responded with. Does that already exist and, if not, how might…

---

## [Could we add a tiny OCaml interpreter to Numworks graphical calculators?](https://discuss.ocaml.org/t/could-we-add-a-tiny-ocaml-interpreter-to-numworks-graphical-calculators/7652)

<div class="topic-metadata">

**Author:** [@Naereen](https://discuss.ocaml.org/u/Naereen)\
**Replies:** 13\
**Last updated:** [October 23, 2024, 3:43pm UTC](https://discuss.ocaml.org/t/could-we-add-a-tiny-ocaml-interpreter-to-numworks-graphical-calculators/7652 "2024-10-23T15:43:52Z")

</div>

Hello there, Let’s start with a teaser: could we add a tiny OCaml interpreter to Numworks (https://www.numworks.com/) graphical calculators?? It should be possible!! I’ve been interested in Python and OCaml since the …

---

## [Toploop doesn't execute valid Ocaml code with escaped strings](https://discuss.ocaml.org/t/toploop-doesnt-execute-valid-ocaml-code-with-escaped-strings/15240)

<div class="topic-metadata">

**Author:** [@homarlone](https://discuss.ocaml.org/u/homarlone)\
**Replies:** 3\
**Last updated:** [September 4, 2024, 5:38am UTC](https://discuss.ocaml.org/t/toploop-doesnt-execute-valid-ocaml-code-with-escaped-strings/15240 "2024-09-04T05:38:41Z")

</div>

Hello, folks. I’m trying to work with compiler-libs.toplevel api’s just to understand a little bit more of the REPL possibilities Ocaml can provide. On the internet, I’ve found this simples function here: let eval cod…

---

## [How can I Toploop inside a script?](https://discuss.ocaml.org/t/how-can-i-toploop-inside-a-script/15175)

<div class="topic-metadata">

**Author:** [@homarlone](https://discuss.ocaml.org/u/homarlone)\
**Replies:** 4\
**Last updated:** [August 22, 2024, 9:33pm UTC](https://discuss.ocaml.org/t/how-can-i-toploop-inside-a-script/15175 "2024-08-22T21:33:04Z")

</div>

Hello Folks, I hope everyone is doing good =\] I’m very new Ocaml and I’m having trouble trying to use Toploop from the compiler-libs in a script, maybe someone here could help. Even tho I’m providing the my dune config…

---

## [Can the double semicolon be removed in the toplevel?](https://discuss.ocaml.org/t/can-the-double-semicolon-be-removed-in-the-toplevel/14942)

<div class="topic-metadata">

**Author:** [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Replies:** 11\
**Last updated:** [July 4, 2024, 5:49pm UTC](https://discuss.ocaml.org/t/can-the-double-semicolon-be-removed-in-the-toplevel/14942 "2024-07-04T17:49:08Z")

</div>

From what I vaguely remember while working on down, this is a bit more tricky than it looks. You need some kind of clear convention to declare to the line editor that you want to issue the code for evaluation. There ar…

---

## [How to know that OCaml toplevel is waiting for user input?](https://discuss.ocaml.org/t/how-to-know-that-ocaml-toplevel-is-waiting-for-user-input/14666)

<div class="topic-metadata">

**Author:** [@aqjune](https://discuss.ocaml.org/u/aqjune)\
**Replies:** 0\
**Last updated:** [May 20, 2024, 7:39am UTC](https://discuss.ocaml.org/t/how-to-know-that-ocaml-toplevel-is-waiting-for-user-input/14666 "2024-05-20T07:39:20Z")

</div>

Is there a robust way to know that a current OCaml toplevel process is (1) waiting for a user input, or (2) it is busy evaluating the previous statement? A naive approach would be to detect # from stdout of course, but…

---

## [\[ANN\] down.0.2.0 and omod.0.4.0](https://discuss.ocaml.org/t/ann-down-0-2-0-and-omod-0-4-0/14380)

<div class="topic-metadata">

**Author:** [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Replies:** 10\
**Last updated:** [May 5, 2024, 7:17am UTC](https://discuss.ocaml.org/t/ann-down-0-2-0-and-omod-0-4-0/14380 "2024-05-05T07:17:19Z")

</div>

It’s my pleasure to announce new releases for down and omod which provide a nice ocaml toplevel user experience upgrade. Simply add to your .ocamlinit: #use "down.top" #use "omod.top" And enjoy all the benefits you ca…

---

## [Open namespace for preprocessor commands automatically?](https://discuss.ocaml.org/t/open-namespace-for-preprocessor-commands-automatically/14463)

<div class="topic-metadata">

**Author:** [@patrick-nicodemus](https://discuss.ocaml.org/u/patrick-nicodemus)\
**Replies:** 2\
**Last updated:** [April 12, 2024, 2:02pm UTC](https://discuss.ocaml.org/t/open-namespace-for-preprocessor-commands-automatically/14463 "2024-04-12T14:02:51Z")

</div>

I am looking at the following project. It seems like it would be cool to port it to OCaml 5, and the authors have had difficulties with the transition, apparently because of the tight integration with internals of the to…

---

## [Fmt module not available in REPL](https://discuss.ocaml.org/t/fmt-module-not-available-in-repl/14374)

<div class="topic-metadata">

**Author:** [@NAlec](https://discuss.ocaml.org/u/NAlec)\
**Replies:** 1\
**Last updated:** [March 28, 2024, 1:27pm UTC](https://discuss.ocaml.org/t/fmt-module-not-available-in-repl/14374 "2024-03-28T13:27:01Z")

</div>

Hi there, I have installed the Fmt module on my windows set up (Dkml install). When I try to open it in the REPL, I get the following errors. Any help welcome PS H:\\OCaml\\plss\> ocaml OCaml version 4.14.0 Enter #help;;…

---

## [How to use "ocaml -stdin"?](https://discuss.ocaml.org/t/how-to-use-ocaml-stdin/14159)

<div class="topic-metadata">

**Author:** [@LocoBeta](https://discuss.ocaml.org/u/LocoBeta)\
**Replies:** 2\
**Last updated:** [February 25, 2024, 1:08pm UTC](https://discuss.ocaml.org/t/how-to-use-ocaml-stdin/14159 "2024-02-25T13:08:45Z")

</div>

Hello everyone, I’m trying to use the “ocaml -stdin” command. The documentation says: “Read the standard input as a script file rather than starting an interactive session.” But when I write “1+1;;” or “print\_int 1;;” o…

---

## [(toplevel) Small terminal screens do not fit and causes rendering error](https://discuss.ocaml.org/t/toplevel-small-terminal-screens-do-not-fit-and-causes-rendering-error/11738)

<div class="topic-metadata">

**Author:** [@anzhi0708](https://discuss.ocaml.org/u/anzhi0708)\
**Replies:** 7\
**Last updated:** [March 21, 2023, 11:28am UTC](https://discuss.ocaml.org/t/toplevel-small-terminal-screens-do-not-fit-and-causes-rendering-error/11738 "2023-03-21T11:28:22Z")

</div>

Summary To save your time, let’s jump to the conclusion: OCaml’s default toplevel / interactive shell probably has some render issues. If you try: 4nji@Gra ~/d/o/pdf\_copypaste\> ocaml OCaml version 5.0.0 Enter #help;; f…

---

## [Displaying module aliases in the toplevel](https://discuss.ocaml.org/t/displaying-module-aliases-in-the-toplevel/11053)

<div class="topic-metadata">

**Author:** [@sanette](https://discuss.ocaml.org/u/sanette)\
**Replies:** 1\
**Last updated:** [December 30, 2022, 4:30pm UTC](https://discuss.ocaml.org/t/displaying-module-aliases-in-the-toplevel/11053 "2022-12-30T16:30:39Z")

</div>

Hi, I don’t understand how the toplevel chooses which module alias to use when displaying types. Consider the following example: file common.ml: type t = { data : string } file a.ml: open Common let make s = { data …

---

## [Ctypes and toplevel error](https://discuss.ocaml.org/t/ctypes-and-toplevel-error/10905)

<div class="topic-metadata">

**Author:** [@sanette](https://discuss.ocaml.org/u/sanette)\
**Replies:** 2\
**Last updated:** [December 3, 2022, 10:04am UTC](https://discuss.ocaml.org/t/ctypes-and-toplevel-error/10905 "2022-12-03T10:04:20Z")

</div>

Hi, I’m struggling with trying to make C-bindings available to the toplevel, using the ctypes library. I tried to replicate the example from this thread: Bytecode compilation, correct invocation · Issue #304 · yallop/oc…

---

## [What happened to \`it\`?](https://discuss.ocaml.org/t/what-happened-to-it/10284)

<div class="topic-metadata">

**Author:** [@hyphenrf](https://discuss.ocaml.org/u/hyphenrf)\
**Replies:** 2\
**Last updated:** [August 10, 2022, 11:31pm UTC](https://discuss.ocaml.org/t/what-happened-to-it/10284 "2022-08-10T23:31:37Z")

</div>

I’m curious about the historic reason for dropping or not porting sml’s it variable in o/caml’s toplevel. At least as far back as 2003 we had the it in sml, maybe people who were programming then can tell me if it was th…

---

## [Equal existential types are not printed equally by the top-level?](https://discuss.ocaml.org/t/equal-existential-types-are-not-printed-equally-by-the-top-level/9370)

<div class="topic-metadata">

**Author:** [@YueLiPicasso](https://discuss.ocaml.org/u/YueLiPicasso)\
**Replies:** 4\
**Last updated:** [February 19, 2022, 6:08pm UTC](https://discuss.ocaml.org/t/equal-existential-types-are-not-printed-equally-by-the-top-level/9370 "2022-02-19T18:08:22Z")

</div>

Below is a small interaction with the top-level. Fisrt define a witness for the integer type. Then define the type for dynamically typed values. Next provide a dynamically typed integer for evaluation. # type \_ ty = I…

---

## [Escaping silently back to repl](https://discuss.ocaml.org/t/escaping-silently-back-to-repl/9136)

<div class="topic-metadata">

**Author:** [@Lindsay](https://discuss.ocaml.org/u/Lindsay)\
**Replies:** 1\
**Last updated:** [January 13, 2022, 7:07am UTC](https://discuss.ocaml.org/t/escaping-silently-back-to-repl/9136 "2022-01-13T07:07:55Z")

</div>

When using the toplevel (standard or utop), is there an exception that one can raise (or some other mechanism) that will exit evaluation and return to the repl without reporting an error? The exception Toploop.PPerror w…

---

## [Native toplevel linked with native libraries](https://discuss.ocaml.org/t/native-toplevel-linked-with-native-libraries/8376)

<div class="topic-metadata">

**Author:** [@zhtprog](https://discuss.ocaml.org/u/zhtprog)\
**Replies:** 4\
**Last updated:** [August 29, 2021, 4:27am UTC](https://discuss.ocaml.org/t/native-toplevel-linked-with-native-libraries/8376 "2021-08-29T04:27:52Z")

</div>

At the most primitive level, with a closed universe of types and values defined in the libraries, we can build a basic interpreter (a giant switch table) and process an expression into a call graph and evaluate the expre…

---

## [Trouble loading cma with Topfind](https://discuss.ocaml.org/t/trouble-loading-cma-with-topfind/6761)

<div class="topic-metadata">

**Author:** [@pveber](https://discuss.ocaml.org/u/pveber)\
**Replies:** 5\
**Last updated:** [November 14, 2020, 9:02am UTC](https://discuss.ocaml.org/t/trouble-loading-cma-with-topfind/6761 "2020-11-14T09:02:06Z")

</div>

Hi all, I’m experimenting with compiler-libs.toplevel and findlib for some project, and I’m puzzled by the following problem. The following code loads the plplot library and calls a function from the library: let eval\_…

---

## [Camlp4r : using a correct end of phrase (single semicolon) in OCaml REPL](https://discuss.ocaml.org/t/camlp4r-using-a-correct-end-of-phrase-single-semicolon-in-ocaml-repl/4532)

<div class="topic-metadata">

**Author:** [@Luc\_ML](https://discuss.ocaml.org/u/Luc_ML)\
**Replies:** 14\
**Last updated:** [October 15, 2019, 9:54pm UTC](https://discuss.ocaml.org/t/camlp4r-using-a-correct-end-of-phrase-single-semicolon-in-ocaml-repl/4532 "2019-10-15T21:54:58Z")

</div>

I’m currently working with some code using camlp4r. When I use the Emacs buffer with Tuareg mode, and I call ocaml (Run OCaml REPL or Evaluate phrase), it’s ok when using ordinary/normal OCaml syntax (directive #camlp4o)…

---

## [Testing \`#use\` directives](https://discuss.ocaml.org/t/testing-use-directives/3957)

<div class="topic-metadata">

**Author:** [@ejgallego](https://discuss.ocaml.org/u/ejgallego)\
**Replies:** 1\
**Last updated:** [June 19, 2019, 1:26pm UTC](https://discuss.ocaml.org/t/testing-use-directives/3957 "2019-06-19T13:26:23Z")

</div>

Dear all, in our CI, we try to test that our debug / toplevel script files do work correctly. For example these are used to install printers, define utility functions, etc… However, we hadn’t found a reliable way to che…

---

## [Providing toplevel pretty-printers for functors](https://discuss.ocaml.org/t/providing-toplevel-pretty-printers-for-functors/2215)

<div class="topic-metadata">

**Author:** [@cfcs](https://discuss.ocaml.org/u/cfcs)\
**Replies:** 0\
**Last updated:** [June 29, 2018, 4:46pm UTC](https://discuss.ocaml.org/t/providing-toplevel-pretty-printers-for-functors/2215 "2018-06-29T16:46:30Z")

</div>

Pretty-printers are provided to the toplevel using the Toploop module, in ipaddr this is done as follows: let printers = \[ "Mymodule.pp" \] let eval\_string ?(print\_outcome = false) ?(err\_formatter = Format.err\_form…
