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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With