Questions tagged [ocaml-toplevel]

ocaml-toplevel refers to the toplevel that ships with the OCaml compiler, and is invoked with the `ocaml` command. Not to be confused with [tag:utop], which is an improved toplevel that must be installed separately. This tag refers to the ocaml toplevel specifically, not the general concept of a toplevel as it relates to OCaml.

ocaml-toplevel is a toplevel (ie. a REPL) that ships with , and is invoked with the ocaml command.

Also see , the improved toplevel for OCaml.

Useful resources

24 questions
5
votes
1 answer

ocaml command line cannot not find "topfind"

I have top-level installed, and have $OCAML_TOPLEVEL_PATH setup. export OCAML_TOPLEVEL_PATH=/Users/smcho/.opam/system/lib/toplevel I checked that the directory exists, and has one file topfind. This is my ~/.ocamlinit file content. #use…
prosseek
  • 182,215
  • 215
  • 566
  • 871
5
votes
3 answers

OCaml: measure execution time in toplevel

How should we measure the execution time of a function in the OCaml toplevel?
UnSat
  • 1,347
  • 2
  • 14
  • 28
5
votes
1 answer

OCaml toplevel print current directory?

Within OCaml toplevel I am trying to print the current directory. i.e. # Filename.current_dir_name;; which returns - : string = "." which is not very useful. What is the toplevel command needed to display the full path of the current directory?
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
4
votes
1 answer

ocaml bitstring within a script

In ocaml toplevel, I can use "bitstring" package by typing the following commands: #use "topfind";; #camlp4o;; #require "bitstring.syntax";; let data = 0l;; let bits = BITSTRING { data : 32 };; However, if I create an OCaml script, e.g., foo.ml…
3
votes
1 answer

How do I get the last evaluated expression in OCaml's toplevel?

How do I refer to the last evaluated expression in OCaml's toplevel repl? I.e. JavaScript uses $_, python uses _, and haskell ghci uses it.
Alex Coleman
  • 607
  • 1
  • 4
  • 11
3
votes
1 answer

Ocaml code which compiles, but does not go with toplevel

I am doing an exercise of a free course. The following ocaml code compiles when I "make", but it complains once I am trying to put it into toplevel. Why? let main () = (* Parsing arguments *) let f_name = ref "" in Arg.parse [ ] (fun s ->…
zell
  • 9,830
  • 10
  • 62
  • 115
3
votes
1 answer

Why am I able to add any number of ; at the end on the line in OCaml top-level?

I'm new to OCaml and I wonder how this statement works: # 1 + 1 ;;;; - : int = 2 # 1 + 1 ;;;;;;;; - : int = 2 Is the ;;;; considered as combining 1+1 with blankas in (((1 + 1);););;? Or is ;;;; treated as a multi-character in some other way?
3
votes
1 answer

How to show a list with large length in ocaml (toplevel)

I have created a list that contains a lot of elements in ocaml and I want to see whats inside it, but ocaml is only showing me a small part of it like this: [e1,e2,e3;...]. How can I configure ocaml to show everything?
ZoCode
  • 51
  • 7
3
votes
1 answer

Inputing data in OCaml toplevel runnin under Emacs

When interactively running the OCaml toplevel on Emacs (via the Tuareg mode), evaluation of expression which do input from the standard input channel does not finish. For instance, when I enter the following expression in the *ocaml-toplevel* buffer…
Romildo
  • 545
  • 9
  • 20
3
votes
1 answer

How to print function calls and backtrace in the toplevel?

I'm trying to get the backtrace of function calls. I wonder if anyone knows how to do that in the toplevel.
Robert White
  • 125
  • 1
  • 5
3
votes
3 answers

What other OCaml top level programs exist? (Vista)

I'm using OCamlWinPlus v1.9RC4. It sucks pretty hardcore. It's constantly crashing, and lacks basic features. What other toplevel OCaml programs can be recommended for Windows Vista?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
2
votes
1 answer

Is it possible to trace auxiliary functions in the Ocaml REPL

What I would like to do is trace the function aux that has restricted scope in a definition like: let example = function arg -> let rec aux = (* some recursive function body*) in aux arg ;; with #trace or a similar…
Naja
  • 45
  • 5
2
votes
2 answers

Why syntax error in this very simple print command

I am trying to run following very simple code: open Str print (Str.first_chars "testing" 0) However, it is giving following error: $ ocaml testing2.ml File "testing2.ml", line 2, characters 0-5: Error: Syntax error There are no further details…
rnso
  • 23,686
  • 25
  • 112
  • 234
2
votes
1 answer

How to load toplevel modules silently

In my ~/.ocamlinit, I have some directives: #use "topfind" #thread #require "core.top" As a result, every time the OCaml toplevel (i.e. ocaml) starts, I get this huge wall of text: OCaml version 4.02.3 Findlib has been successfully loaded.…
Flux
  • 9,805
  • 5
  • 46
  • 92
2
votes
2 answers

ocaml command line cannot find “topfind”

I've installed opam, run opam init, run opam switch 4.06.0 which created a 4.06.0 directory inside ~/.opam, run "eval opam confing env" which exports $OCAML_TOPLEVEL_PATH as ~/.opam/4.06.0/lib/toplevel amongst other things, when launching ocaml I…
Nobilis
  • 7,310
  • 1
  • 33
  • 67
1
2