[MLton] Show type at point / OCaml -dtypes

Stephen Weeks MLton@mlton.org
Tue, 26 Jul 2005 18:13:16 -0700


> Both the Caml and the Tuareg modes for Emacs provide the function "Show
> type at point", which looks up and shows the type of the expression under
> the point using the annot-file.
...
> I was wondering if there exists a similar tool for SML.

Nothing in MLton.  All we've got are -show-basis and -show-def-use.

> If not, I think it would be a very useful addition to MLton to
> generate type annotation files and (for SML mode) to implement "Show
> type at point" using the generated files.

I agree; -show-types would be nice.  It doesn't seem too hard.  One
could tweak elab{Exp,Pat} in elaborate-core.fun to add to some global
list a pair of the region and the type.  Then, once type inference is
complete, spit out all the pairs to the file.

One issue I see is how to choose names for type constructors.  MLton's
front end uses a very expensive algorithm to do this in type error
messages, which is reasonable because good names are very helpful and
because it is limited to 20 errors at a time.  The front end's
approach is to find the shortest name for a type for each error by
looking over the entire environment in scope at the point of the
error.  One consequence of this is that the same type may have
different names in different error messages.

Perhaps a reasonable compromise would be to choose tycon names on a
per-file basis.  That is, at the start of each file, call
Env.setTyconNames and then walk over the environment checkpointing all
the names.  Store the checkpoint in the global list of pairs to use
for printing the types in this file.