4

Where is the documentation for functions, symbols under Core.Std ?

Or, is there any conventional way to look up ocaml documentation rather than guessing in utop REPL ?

E.g. I know if open Core.Std, then the function String.split will be imported. But it's hard to find out what's the function parameter etc.

Also, Ocaml don't have source code links to it's documentation like Haskell does, I guess.

The current best solution is looking at: https://ocaml.janestreet.com/ocaml-core/111.28.00/doc/core_kernel/#Core_string

CodeFarmer
  • 2,644
  • 1
  • 23
  • 32

1 Answers1

3

Merlin is able to perform documentation lookup and jump to the definition. In Emacs, I'm assuming, that you're using Emacs, the documentation lookup is not bound by default to any key, so I bound it to C-c C-d. Add the following to your emacs configuration file:

(define-key merlin-mode-map (kbd "C-c C-d") 'merlin-document)
(define-key merlin-mode-map (kbd "C-c d") 'merlin-destruct)

The lookup function will jump directly to the mli file. This is my favorite way of reading the documentation. Unfortunately, due to a bug, Janestreet stopped to ship the mli file, so the feature is somewhat broken with the core. As a workaround, you can install source code with

opam source core_kernel

And then create a .merlin file, and point it to the sources:

S <path-to-sources>

Usually, it would be something like this

S ../core_kernel.113.33.00/src

Note, you should point merlin directly to the source subfolder.

It is also worth noting, that Merlin has intellisence like completion, that helps a lot, and you can hit F1 when you choose an entry from a completion list, and a window with documentation will pop up.

And finally, the link to the documentation, that you're referencing is very outdated. Here is the link to the latest documentation.

ivg
  • 34,431
  • 2
  • 35
  • 63
  • 3
    If you're using vim, `:MerlinDocument` can do the same – hcarty Jun 20 '16 at 17:02
  • @CodeFarmer Adding `PKG core` to `.merlin` (instead of `S `) kind of solves the problem with getting docs. TLDR: `merlin-document` works for *fully-qualified* names. In Emacs: type `Core.Std.String.split`, hit `M-x`, then `merlin-document` will display the documentation. If I `open Core.Std` then `merlin-document` doesn't work for `String.split`. – Anton Trunov Jun 21 '16 at 15:05
  • `PKG core` should be there of course, but it is not enough for the lookup to work after version `113.33`, as the `mli` is not shipped anymore. This is just because, there is no `mli` to land in. So `S ` just gives an alternate place were merlin can land. – ivg Jun 21 '16 at 17:27
  • `opam list core`'s output: `core 113.33.02+4.03 ...`, it works without `mli`'s. Merlin v2.5.0 (OCaml 4.03). It seems merlin can extract the documentation from `.opam//lib/core_kernel/core_string.cmti`. – Anton Trunov Jun 21 '16 at 19:10
  • @Anton, `merlin-document` works, I'm talking about `merlin-locate`. The former works, the latter does not. Yes, the docstrings are in the `cmti`. – ivg Jun 21 '16 at 19:56
  • If I add `S ` to my `.merlin` file, `merlin-locate` jumps to the corresponding `ml` file (not `mli`). – Anton Trunov Jun 21 '16 at 20:21
  • 1
    That is controlled by the `merlin-locate-preference` variable. Set it to `'mli` and you will get the `'mli`. – ivg Jun 21 '16 at 20:35