logo       

Re: The simplest program: msg#00039

lang.haskell.glasgow.bugs

Subject: Re: The simplest program

Axel Simon wrote:

This bug is older! ghc 5.04 does not enforce that the return type of main
is (). In fact with 5.04 you can return anything you want and get very
fancy exception on termination if you return a more complex data type.

I don't know about an exception on termination (Is it a known bug? If not, it should be reported), but returning anything is allowed. The Haskell Report, section 5, says:

A Haskell program is a collection of modules, one of which, by convention, must be called Main and must export the value main. The value of the program is the value of the identifier main in module Main, which must be a computation of type IO t for some type t (see Section 7). When the program is executed, the computation main is performed, and its result (of type t) is discarded.

The problem with that no-op program is that the type checker doesn't seem to know that main has to be in the IO monad.
On the other hand...

> module Main where
> main :: Monad m => m ()
> main = return ()

is legal according to both GHC 5.04 and 5.05. Now I'm beginning to see why GHC complains.
It would be nice, though, if "main = return ()" was legal without additional type signatures. I've been bitten by this before: I wrote some datatypes and functions in a "Main" module, but I left the main action empty at first. Then I just wanted to check syntax and typing and got a strange error message...

Cheers,

Wolfgang


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise