Questions tagged [utop]

utop (Universal toplevel) is an improved toplevel (REPL) for OCaml. Not to be confused with [tag:ocaml-toplevel] which ships with the OCaml compiler.

utop is an improved toplevel for . It can run in a terminal or in . It supports line editing, history, real-time and context sensitive completion, colors, and more.

Useful resources

93 questions
4
votes
1 answer

What toplevel directives does utop support?

I can't find any documentation on what toplevel directives I can use in utop. All I could find is this list of directives supported by the default ocaml toplevel, but that list doesn't seem to be complete for utop and is missing things like #typeof,…
hugomg
  • 68,213
  • 24
  • 160
  • 246
3
votes
1 answer

dune utop some executable

For an single file executable, how can I load it in dune utop ? Precisely, on a project with a library in a directory lib and a corresponding dune file, I can launch dune utop lib then open Lib.MyModule and this will load the file MyModule.ml. What…
nicolas
  • 9,549
  • 3
  • 39
  • 83
3
votes
1 answer

Loading a module with dependencies in utop

I have two modules A.ml and B.ml like so: A.ml: type t = int let from_int (i : int) : t = i B.ml: open A let my_t : t = from_int 0 I can compile them just fine by invoking ocamlc A.ml B.ml however I have no idea how to load them both in utop in…
gallais
  • 11,823
  • 2
  • 30
  • 63
3
votes
1 answer

OCaml's utop: importing external modules

I'm interested in introducing Angstrom, a parsing combinator library, to a project of mine. I installed Angstrom to my system with opam as follows: $> opam install angstrom I also successfully compiled the project with reference to the module in…
David Shaked
  • 3,171
  • 3
  • 20
  • 31
3
votes
1 answer

Standard .ocamlinit configuration

I thought I set this up correctly, like explained on realworldocaml, but when I try to do open Core;; I get Unbound module Core I think this is related to .ocamlinit, but I don't know what else should I add / remove from it. #use…
icebp
  • 1,608
  • 1
  • 14
  • 24
3
votes
3 answers

utop error: No such package: sexplib.syntax - required by `core.syntax'

I'm trying to set up an emacs ocaml environment following the Real World Ocaml instructions here, but when I start utop I get the error: No such package: sexplib.syntax - required by `core.syntax' If I run: ocamlfind list | grep sexp from the…
BillyBadBoy
  • 552
  • 3
  • 18
2
votes
2 answers

Receiving Stdlib.Scanf.Scan_failure : character '\\n'

I downloaded and executed utop as guided here, and I ran the following code: Scanf.scanf "%d %d" (fun a b -> Printf.printf "%d\n" (a - b));; On the first time I input 3 1, it worked fine, giving 2 - : unit = (), but after the second try with the…
2
votes
1 answer

How to use ppx derive in utop?

How can I use ppx derive (https://github.com/ocaml-ppx/ppx_deriving) in my utop? For example, I have to following code: module A = struct module T = struct type t = int [@@deriving hash, sexp, compare] end include…
David 天宇 Wong
  • 3,724
  • 4
  • 35
  • 47
2
votes
1 answer

utop and printing constructors

When loading up code in utop (or dune utop) and printing any data constructor like Bin.Stop with #show Bin.Stop;; I get a crash. utop # #show Bin.Stop;; >> Fatal error: Ident.rename Bin.nat Fatal error: exception Misc.Fatal_error ~ via v4.12.0…
nicolas
  • 9,549
  • 3
  • 39
  • 83
2
votes
1 answer

Why my OCaml "=" operator is only applied to int?

I use vscode, with extensions of "OCaml and Reason IDE" Here is my result in utop: utop # 1. = 1. ;; Line 1, characters 0-2: Error: This expression has type float but an expression was expected of type int And also for String: utop…
2
votes
1 answer

What is the type "int/2" in OCaml

When I executed the following commands in the interaction environment (either OCaml or utop), all the expressions of "int" type turned out to be "int/2" type. This behaviour can be replicated as follow. # 3;; - : int = 3 # type int;; type int #…
2
votes
1 answer

use packages installed with opam inside utop

I installed yojson with opam: opam install yojson and I want to use it inside utop, but I haven't been able to make it work. I've tried these commands inside utop and none of them worked (it complains that it can't find the file / package): #use…
yewang
  • 585
  • 7
  • 14
2
votes
1 answer

How to move cursor in a multiline comand in utop?

How can I move my cursor in a multiline command in utop? E.g : utop # let ratio x y = let open Float.O in of_int x / of_int y ;; After I execute the above command, if I want to edit the line "let open...", I must press up arrow once then press…
Hai Hoang
  • 1,207
  • 2
  • 18
  • 35
2
votes
1 answer

How to use a bucklescript library with rtop in an esy project?

I am attempting to use rtop as repl on an esy project. In order to do so, I have added "@esy-ocaml/rtop":"*" to the devDependencies section of my package.json file, and tried to start rtop with esy rtop: { ..., "dependencies": { "react":…
Pedro Rolo
  • 28,273
  • 12
  • 60
  • 94
2
votes
1 answer

@@deriving sexp is not working on utop

I'm running this code in utop: # type u = { a: int; b: float } [@@deriving sexp];; But the expected declarations of s-expression converters are not generated. I have Core 0.11.0 and utop version 2.1.0 installed. the version of Ocaml is…
javier
  • 1,705
  • 2
  • 18
  • 24