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

2019-02-22 05:45发布

问题:

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.

回答1:

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.