Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you inspect the type of (*) on OCaml's toplevel?

Tags:

comments

ocaml

I wanted to see the type of the multiplication function (*), so I tapped it into the OCaml toplevel.

# (*)

However, the toplevel echoed:

(*);; 1: this is the start of a comment.

and then consumed any further input I put in. I figured that I had to get out of the comment mode by pressing Ctrl+d to send EOF. Great. But surely, I should be able to query the type of any function, including our mysterious multiplication function (*)?!

I would be incredibly disappointed if that is a limitation of the toplevel.

like image 794
fatuhoku Avatar asked Feb 27 '11 17:02

fatuhoku


People also ask

What is toplevel in OCaml?

In short, the toplevel is OCaml's Read-Eval-Print-Loop (repl) allowing interative use of the OCaml system. You can consider the toplevel an alternative to compiling OCaml into an executable.

How do I get out of toplevel OCaml?

In a terminal window, type utop to start the interactive OCaml session, commonly called the toplevel. Press Control-D to exit the toplevel. You can also enter #quit;; and press return.

What does in mean OCaml?

in" is used to name values used throughout * the computation (i.e., to make local variables). *) let alen = List.length a in let blen = List.length b in if alen < blen then -1 else if alen > blen then 1 else 0 let rec split list = (* Here "let ... in" is used to name * the parts of an intermediate result.


1 Answers

It does recognize *) as the end of the comment, but it's still waiting for the end of the expression. I.e. if you enter two semicolons, it will give you a syntax error and allow you to enter another expression.

To get the function * type ( * );; with spaces to distinguish it from comment symbols.

like image 122
sepp2k Avatar answered Nov 09 '22 11:11

sepp2k