Have you ever been confused by the type error messages produced by OCaml?
If you have, you might have wondered why the OCaml compiler does not
produce better error messages.
The reason is: it can't.
During type inference, the OCaml compiler finds a type conflict
between two subexpressions: one requires one type and the other
provides a different type.
However, there is no way for the OCaml compiler to know
which of the two types is the right type for the programmer.
Thus, the OCaml compiler arbitrarily chooses one of them and reports
it as a type error.
The Type Debugger in this page improves on this situation by
asking questions to the programmer.
From the answers to the questions, it understands the programmer's
intention and leads the programmer to the real source of the type
error.
This idea of asking questions to obtain programmer's intention
is due to Shapiro's algorithmic program debugging and is used
by Chitil to design a type debugger for a small subset of Haskell.
We extend this approach to support full OCaml by reusing the type
inferencer in the OCaml compiler.
The Type Debugger has been used successfully in the functional
programming course in Ochanomizu University.
Environments
We are developing the Type Debugger using the following environments:
Download autoload.vim,
rename it to typedebugger.vim,
edit lines 20 and 25 appropriately
(if the default ocaml binary is not the type debugger),
and place it under .vim/autoload/ in your home directory.
Download plugin.vim,
rename it to typedebugger.vim,
edit line 11 appropriately
(if the default ocaml binary is not the type debugger),
and place it under .vim/plugin/ in your home directory.
To start the type debugger:
Type :TypeDebuggerStart to launch the type debugger.
Type :TypeDebuggerCompile to compile using
make with the type debugger.
To debug:
To answer Yes
type (backslash followed by y) or :TypeDebuggerSendYes.
To answer No
type (backslash followed by n) or :TypeDebuggerSendNo.
To answer Quit
type (backslash followed by q) or :TypeDebuggerSendQuit.
To answer Exit
type (backslash followed by e) or :TypeDebuggerExit.
Papers and talks
Asai, K.
``Principle and Practice of OCaml Type Debugger,''
presented at the ACM SIGPLAN Programming Languages Mentoring Workshop
at ICFP (September 2016).
abstract,
slides,
YouTube
Ishii, Y., and K. Asai
``Report on a User Test and Extension of a Type Debugger for
Novice Programmers,''
3rd International Workshop on Trends in Functional Programming in
Education
(June 2014).
Post conference version
in Electronic Proceedings in Theoretical Computer Science 170,
pp. 1-18 (December 2014).
Tsushima, K.
``Practicable type debugging for functional languages,''
PhD thesis, Department of Information Science, Ochanomizu University
(September 2013).
PDF
Tsushima, K., and K. Asai
``An Embedded Type Debugger,''
The 24th Symposium on Implementation and Application of Functional
Languages, Oxford (August 2012).
abstract.
Post conference version in
LNCS 8241, pp. 190-206 (2013).
Received Peter Landin Prize.