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
2
votes
2 answers

Why is `;;` giving me a syntax error in utop?

I'm working on a short project to convert small programs from python to java and visa versa. I created the following code, and tested it in utop. let c = let x = "for (int i = 0; i<10; i++)" and y = "for i in range(0,10):" in function | x -> y | y…
Mark Puchala II
  • 634
  • 2
  • 8
  • 25
2
votes
1 answer

OPAM and OCaml installation

I'm having some problems setting up my OCaml environment set up, and am following this page: https://github.com/realworldocaml/book/wiki/Installation-Instructions However, I'm having some problems that I can't resolve. I'm on macOS 10.12.5 and am…
2
votes
1 answer

Print values nicely in utop

Haskell's ghci can print nicely any value belonging to a type that implements Show typeclass. Is there any equivalent in OCaml that lets utop automatically print values of user-defined types nicely? Typing x |> M.to_string every line is quite…
Sventimir
  • 1,996
  • 3
  • 14
  • 25
2
votes
1 answer

Change utop output width

When displaying long lists and other large values, utop wraps them at about 80 columns, even when my terminal window is wider. How can I change the output width? The only thing that I have found that might have provided the solution is UTop.size,…
Mars
  • 8,689
  • 2
  • 42
  • 70
2
votes
2 answers

Absolute value of float in ocaml

When I use the function abs_float, Merlin (running in emacs) tells me: Warning 3: deprecated: Core.Std.abs_float [since 2014-10] Use [Float] (The code still compiles, though.) What is this trying to tell me? I've tried Float.abs and similar variants…
fmg
  • 813
  • 8
  • 18
2
votes
2 answers

How do I setup ocamlinit so that ppx works?

This is my ocamlinit: (* Added by OPAM. *) let () = try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") with Not_found -> () ;; (* ## added by OPAM user-setup for ocamltop / base ## 3ec62baf6f9c219ae06d9814069da862 ## you can edit, but…
ackerleytng
  • 416
  • 6
  • 17
2
votes
1 answer

Print history list with ocaml utop

Is there a way to print the history list in utop, like calling history from bash? I haven't found any sort of history ring associated with utop-mode in emacs either. I'm trying to use the history to hippie-expand against in the REPL. Utop appears…
Rorschach
  • 31,301
  • 5
  • 78
  • 129
2
votes
1 answer

Getting error when try to pattern match for Unix_error (Ocaml)?

I've been trying to pattern for the case where a user types in an invalid directory: # let dir = Unix.opendir "adfalf";; Exception: Unix.Unix_error (Unix.ENOENT, "opendir", "adfalf"). My function is as follows: let files_of_dir d = try …
14wml
  • 4,048
  • 11
  • 49
  • 97
2
votes
1 answer

utop: Error: Reference to undefined global `Grammar'

I want to check the info of Coq grammar so I loaded grammar.cma into utop: #load "/home/xxx/.opam/system/lib/coq/grammar/grammar.cma";; but there's an error: Error: Reference to undefined global `Grammar' Coq version: 8.5.0 OCaml version:…
Pallar Pak
  • 23
  • 2
2
votes
0 answers

Trouble installing OPAM on ubuntu 14

To install OPAM (with ocaml already installed) I followed this guide: https://github.com/realworldocaml/book/wiki/Installation-Instructions. Here are the steps I made to install OPAM $ sudo add-apt-repository ppa:avsm/ppa $ sudo apt-get update $…
Leoking938
  • 71
  • 1
  • 2
  • 11
2
votes
2 answers

OCaml string length limitation when reading from stdin\file

As part of a Compiler Principles course I'm taking in my university, we're writing a compiler that's implemented in OCaml, which compiles Scheme code into CISC-like assembly (which is just C macros). the basic operation of the compiler is…
asafc
  • 357
  • 3
  • 21
1
vote
1 answer

Why mark stag functions are not called here?

I am trying to understand the following behaviour of OCaml Format module and semantic tags. My code: let prepare_ppf ppf = let original_stag_functions = Format.pp_get_formatter_stag_functions ppf () in let original_mark_tags_state =…
Anentropic
  • 32,188
  • 12
  • 99
  • 147
1
vote
1 answer

Ocaml utop does not (but does) recognise Big_int

I have some code that uses the module Big_int, like in: open Big_int;; Big_int.gcd_big_int 5 6;; However, when I compile this with utop dune utop --release (I use release to avoid some warnings), then I get this error: Error: Required module…
Theo Deep
  • 666
  • 4
  • 15
1
vote
1 answer

Alt + Left and Alt + Right allows me to switch between autocompletes in Utop, but tab will go back to first selection

In OCaml's utop, I can use alt+left or alt+right to move through autocomplete sections, but when I click tab to autocomplete the first selection is used. What do I do?
jshusko
  • 35
  • 4
1
vote
1 answer

Unable to use Float module in Utop

I'm trying to use the Float Module in Utop, however whenever I try to open it in Utop by doing this : open Float;; Error: Unbound module Float I get this error I'm using OCaml version 4.05.0, Utop version 2.2.0 (Utop is using 4.05.0 as well, just…
TierTwo
  • 123
  • 2
  • 11