# Quickly viewing OCaml function documentation

**URL:** <https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120>\
**Category:** Learning\
**Tags:** documentation\
**Created:** [January 7, 2022, 11:55pm UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120 "2022-01-07T23:55:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mndrix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mndrix/32/3463_2.png) [@mndrix](https://discuss.ocaml.org/u/mndrix)\
**Post date:** [January 7, 2022, 11:55pm UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/1 "2022-01-07T23:55:00Z")

</div>

I’m new to OCaml and was previously accustomed to `man open` (C) or `go doc os open` (Go) to view documentation for a specific function. It looks like maybe `ocp-index print` is the OCaml equivalent. I wrote a shell function to make the UI more to my liking. Am I missing a better tool than `ocp-index`?

Here’s my shell function, in case anyone’s interested:

```auto
od() {
    usage="usage: od [-s] identifier"
    if [$# -eq 0]; then
        echo "$usage"
        return 1
    elif ["$1" = "-s"]; then
        shift
        if [$# -eq 0]; then
            echo "$usage"
            return 1
        fi
        tmp=$(mktemp -t od-XXXXXX)
        if ! ocp-index locate "$1" >"$tmp"; then
            echo "Found nothing"
            return 1
        fi
        IFS=: read path line column <"$tmp"
        uctags --language-force=OCaml -f - "$path" >"$tmp"
        less -T "$tmp" +$line "$path"
        rm "$tmp"
    else
        ocp-index print "$1"
    fi
}

```

Usage: `od open_in` shows the documentation for opening a file. `od -s open_in` lets me read the source in a pager. After seeing that `open_in` is a wrapper around `open_in_gen`, I type `-t open_in_gen` (in `less`) to jump to the definition. So far, Universal Ctags seems pretty accurate for OCaml.

---

<div class="post-metadata">

**Author:** ![Gopiandcode](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/gopiandcode/32/5346_2.png) [@Gopiandcode](https://discuss.ocaml.org/u/Gopiandcode)\
**Post date:** [January 9, 2022, 8:10am UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/2 "2022-01-09T08:10:03Z")

</div>

If you use GNU+Emacs and use Merlin for type information, the merlin emacs package defines a function `merlin-document` which brings up the documentation for a given function in a separate buffer. For some reason this isn’t bound by default, but I find `C-c C-h` is a good option for quick usage:

```auto
       (bind-key (kbd "C-c C-h") #'merlin-document tuareg-mode-map)

```

---

<div class="post-metadata">

**Author:** ![ancolie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/ancolie/32/6189_2.png) [@ancolie](https://discuss.ocaml.org/u/ancolie)\
**Post date:** [January 10, 2022, 9:54am UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/3 "2022-01-10T09:54:05Z")

</div>

Note that stdlib modules are available with `man`. To have the doc for `open_in` you can do `man Stdlib`. For another module it’s the same, e.g. `man Ephemeron`.

---

<div class="post-metadata">

**Author:** ![n4323](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@n4323](https://discuss.ocaml.org/u/n4323)\
**Post date:** [January 10, 2022, 10:09am UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/4 "2022-01-10T10:09:16Z")

</div>

obligatory ‘Vim-has-it-too’ comment: in Vim it’s `:MerlinDocument`. Also, in case you have not found that yet, `odig` provides browsable API docs. Install it by opam, then `odig doc` generates local html documentation which should open in your browser with a global index of installed packages. `odig doc <package>` is more direct. Some people like to use CLI browsers to view odig documentation.

---

<div class="post-metadata">

**Author:** ![mndrix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mndrix/32/3463_2.png) [@mndrix](https://discuss.ocaml.org/u/mndrix)\
**Post date:** [January 10, 2022, 1:53pm UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/5 "2022-01-10T13:53:27Z")

</div>

> [@Gopiandcode](#):
>
> If you use GNU+Emacs

I do use emacs (somewhat grudgingly because of its bloat), so I may try Merlin. Thanks for the tip.

---

<div class="post-metadata">

**Author:** ![mndrix](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mndrix/32/3463_2.png) [@mndrix](https://discuss.ocaml.org/u/mndrix)\
**Post date:** [January 10, 2022, 10:19pm UTC](https://discuss.ocaml.org/t/quickly-viewing-ocaml-function-documentation/9120/6 "2022-01-10T22:19:42Z")

</div>

I spent some time today using Merlin integration in emacs. I’m a convert: it was surprisingly snappy and productive. Thanks again @Gopiandcode and @n4323 for the helpful suggestions.

Also, in case these keywords help others locate this topic later, the tools in this thread are also a good substitute if you’re accustomed to commands like `pydoc open` or `perldoc -f open`.
