Live update of source with inferred type?

(A pie-in-the-sky wish.) Personally, I love automatic type inference and generics a la ML, Haskell etc. I wish such systems would go one step further and offer an optional means of annotating the code I'm writing after the type inference happens; that way when reading code for the first time one would get the benefit of knowing what things are when they are first introduced, without having to divine it from how they are then used. I do not know of anything that does this, but would love to hear if there is such a system (or if there are evil Emacs hack ideas along such lines).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


The">Clean IDE for MS Windows, does not add inferred types to the source file.

The IDE provides a separate window which lists out the type inference results, for example

min` :: .Int
bottomup :: !Int !Int -> .(Tree Int)
itemcheck :: !(Tree .Int) -> Int
showItemCheck :: a !(Tree .Int) b *File -> .File | toString a &  .File | toString b & toString a
sumloop :: !Int !Int !Int -> Int
showCheck :: !.Int a !Int !*File -> .File | toString a
showCheck :: !.Int !Int !Int !*File -> .File
depthloop :: !Int !Int !*File -> .File
showItemCheck :: !Int !(Tree .Int) a *File -> .File |  .File
_c;51;16 :: !Bool Int Int -> Int
Start :: !*World -> .World

Clean looked very interesting...

...back when I tried it out, maybe a few years ago now? The main drawbacks I had with it were that a) it forced me to use their severely lame IDE and b) it did not have a debugger. The latter is absolutely required to me, and former only served to make me very frustrated. Hopefully Clean can keep on truckin' and eventually get to a state that is more user friendly, and/or disseminate its ideas out to other systems. The 2D platform games written in Clean are great!

OCaml does it

... with a compiler flag. It dumps all the inferred types in a file. With Emacs, you just press C-c C-t and you get the type of the expression under point in the message area. It works pretty well.

Dump detailed type information. The information for file is put into file x.annot. In case of a type error, dump all the information inferred by the type-checker before the error. The x.annot file can be used with the emacs commands given in emacs/caml-types.el to display types interactively.

O'Caml doesn't like me

O'ch! I've tried to install and use O'Caml a couple of times now, and have met - either sooner or later - with frustrating broken-ness-itude. Since my life on this Earth is short, I've totally given up on it (my loss). I hope that the idea eventually permiates to other systems!