# Code readability - How to view signature and documentation of a module?

**URL:** https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477
**Category:** Learning
**Tags:** ide, module, readability, functor
**Created:** [January 23, 2018, 7:05pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477 "2018-01-23T19:05:04Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)
#### Post date: [January 23, 2018, 7:05pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/1 "2018-01-23T19:05:04Z")

</div>

I wrote this line:

```auto
module Tbl = Core_kernel.Std.Hashtbl.Make (Bap.Std.Exp)

```

For the sake of generality, let’s rewrite this as:

```auto
module Out = Lib.Make (In)

```

What is a good, systematic way of viewing the _signature_ and the _documentation_ of the modules `Out` and `In`, and of the functor `Lib.Make`?

The person viewing the code being…

- someone who’s unfamiliar with OCaml and who doesn’t have a development environment set up, e.g. someone browsing code on GitHub?
- someone having the best OCaml development environment set up for them?

---

<div class="post-metadata">

### Author: ![avsm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/avsm/32/6_2.png) [@avsm](https://discuss.ocaml.org/u/avsm)
#### Post date: [January 23, 2018, 8:15pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/2 "2018-01-23T20:15:46Z")

</div>

Excellent question!

> [@mjambon](#):
>
> someone who’s unfamiliar with OCaml and who doesn’t have a development environment set up, e.g. someone browsing code on GitHub?

For this one, the answer is interface documentation generation. The `odoc` tool does cross-referenced documentation, and is something we (@antron in particular) are actively working on to build a central [docs.ocaml.org](http://docs.ocaml.org) repository where the above interfaces could be browsed. As an example the current (beta) version of odoc running on the MirageOS modules and cross-referencing them can be found at [http://docs.mirage.io](http://docs.mirage.io).

As `odoc` gets more complete in the coming months, we’ll post on this forum to get your feedback on that.

> [@mjambon](#):
>
> someone having the best OCaml development environment set up for them?

[Merlin](https://github.com/ocaml/merlin) should be able to show you all the relevant interfaces from within your editor. Have you given it a spin?

---

<div class="post-metadata">

### Author: ![rauschma](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rauschma/32/730_2.png) [@rauschma](https://discuss.ocaml.org/u/rauschma)
#### Post date: [January 23, 2018, 8:22pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/3 "2018-01-23T20:22:53Z")

</div>

I second Merlin: using it via Visual Studio Code is great.

---

<div class="post-metadata">

### Author: ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)
#### Post date: [January 23, 2018, 9:26pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/4 "2018-01-23T21:26:52Z")

</div>

> [@rauschma](#):
>
> I second Merlin: using it via Visual Studio Code is great.

So far VS Code with the Reason/OCaml extension with Merlin looks amazing. I’m on Ubuntu Linux and I’d be switching over from ~20 years of emacs.

---

<div class="post-metadata">

### Author: ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)
#### Post date: [January 23, 2018, 9:48pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/5 "2018-01-23T21:48:52Z")

</div>

> [@avsm](#):
>
> Merlin should be able to show you all the relevant interfaces from within your editor. Have you given it a spin?

Yes, but it doesn’t work from emacs or the function that does it is buried somewhere and I couldn’t identify it. It works in Visual Studio Code (MIT license, runs on Linux/Mac/Windows) which I just tried out and it’s great.

---

<div class="post-metadata">

### Author: ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)
#### Post date: [January 24, 2018, 7:50am UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/6 "2018-01-24T07:50:14Z")

</div>

Do you know ocp-browser?  
Not sure it does exactly what you want though.

---

<div class="post-metadata">

### Author: ![bobbypriambodo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/bobbypriambodo/32/179_2.png) [@bobbypriambodo](https://discuss.ocaml.org/u/bobbypriambodo)
#### Post date: [January 24, 2018, 8:11am UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/7 "2018-01-24T08:11:51Z")

</div>

> [@mjambon](#):
>
> Yes, but it doesn’t work from emacs or the function that does it is buried somewhere and I couldn’t identify it.

Just in case you’re still wanting to stay at emacs world, the Merlin wiki of [emacs from scratch](https://github.com/ocaml/merlin/wiki/emacs-from-scratch) documents the functions quite well, and you can use [opam-user-setup](https://github.com/OCamlPro/opam-user-setup) to simplify the setup when using multiple switches. Or, in case readers are interested in [Spacemacs](http://spacemacs.org/), it’s only a matter of [adding the `ocaml` layer](https://github.com/ocaml/merlin/wiki/spacemacs-from-scratch) (also includes Spacemacs installation instructions).

---

<div class="post-metadata">

### Author: ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)
#### Post date: [January 24, 2018, 7:03pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/8 "2018-01-24T19:03:57Z")

</div>

> [@bobbypriambodo](#):
>
> the Merlin wiki of emacs from scratch documents the functions quite well

ok, so I found out what I was doing wrong. I had this in my `.emacs`:

```auto
; huh, C-c C-t is overridden by ocp-index-print-info-at-point,
; which kind of does the same thing but misses some type info.
(global-set-key (kbd "C-c t") 'merlin-type-enclosing)

```

which is probably wrong in more than one way. The main problem is that it overrides the original “C-c t” shortcut that would let me see the type of a module.

After commenting out the above, “C-c t” shows me the signature of the module under the cursor in another buffer, which is great. And “C-c C-t” is back to calling `ocp-index-print-info-at-point` which doesn’t fully work and often blocks for several seconds.

For the record, the problematic behavior happens after leaving just this in my `~/.emacs`:

```auto
;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line
(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el")
;; ## end of OPAM user-setup addition for emacs / base ## keep this line

```

The instructions I think I followed and turned into a script for setting up emacs for OCaml development are:

```auto
opam install -y merlin
opam user-setup install
opam install -y ocp-indent ocp-index

# emacs only
opam install -y tuareg

```

Am I installing too much? Did I start from a dirty state? Maybe. The point is that it’s hard to tell.

---

<div class="post-metadata">

### Author: ![mjambon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mjambon/32/6180_2.png) [@mjambon](https://discuss.ocaml.org/u/mjambon)
#### Post date: [January 24, 2018, 7:33pm UTC](https://discuss.ocaml.org/t/code-readability-how-to-view-signature-and-documentation-of-a-module/1477/9 "2018-01-24T19:33:54Z")

</div>

Update: now `merlin-type-enclosing` works for me on module names as well. I have no idea why.
