[jhc] type of main

Daniel Gorín jcpetruzza at gmail.com
Sat Feb 11 06:47:40 CET 2012


Hi

I noticed that jhc is not checking what the type of the main function is. In particular, it rejects this module:

> main = return ()

because the inferred type, Monad m => m () is not monomorphic. This may typically happen if the most general type for main is MonadIO m => m ().

On the other hand, the following module is accepted:

> main :: [()]
> main = return ()

The resulting program does not crash (as I had expected!) but prints [()] instead.

In any case, according to the Haskell 98 Report (sec. 5), main has to be "a computation of type IO t, for some type t". I'm attaching a patch that enforces this (I think) by unifying, during the type-checking, the type of the main function with IO t. 

Daniel

-------------- next part --------------
A non-text attachment was scrubbed...
Name: type-of-main.dpatch
Type: application/octet-stream
Size: 4780 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/jhc/attachments/20120211/66a0ed64/attachment.obj>


More information about the jhc mailing list