Christian Sievers, you wrote:
> Thank you for pointing me to the System library. However, while I was
> indeed implying that there is no way of returning an exit code, my main
> question was which type main should have. You seem not to like IO Int
> (one even for several reasons ;-) but it still l
Thank you for pointing me to the System library. However, while I was
indeed implying that there is no way of returning an exit code, my main
question was which type main should have. You seem not to like IO Int
(one even for several reasons ;-) but it still looks quite natural to me.
Christian
> Nope, returning from main is defined by the C standard to be equivalent
> to calling exit(), as if main() where invoked as `exit(main(argc, argv))'.
Well, it might be standardized, but I've been bitten by implementations
that generate a random exit code if you just return 0 from main.
This was
> Isn't this a Unix-specific convention, to treat the value returned by
> main()
> as the exit value of the process?
Yes, and it only works in some flavours of Unix. The proper
way to exit a C program is to call exit(). The proper way to
exit a Haskell program is to call exitWith.
-- L
Christian Sievers wrote:
> Hello, I just wondered if it was ever considered to let the main function
> have the type IO Int, in order to let the haskell programm be able to
> return an exit code to the calling environment, as C's int main(...)
> does. I think real programms sometimes want to ex
Christian,
In Haskell you can use exitWith :: ExitCode -> IO a from the System library,
so you don't need the program to "return" a "Int" (this is not a
esthetically pleasing in C!). The IO a allows the operation to be used
in any IO monad context, not just IO ().
Regards,
Kevin
At 6:40 pm 21/
> From: Christian Sievers[SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, August 21, 1997 6:59 PM
> To: [EMAIL PROTECTED]
> Subject: how about main :: IO Int
>
> Hello, I just wondered if it was ever considered to let the main
> function
> have the type
Hello, I just wondered if it was ever considered to let the main function
have the type IO Int, in order to let the haskell programm be able to
return an exit code to the calling environment, as C's int main(...)
does. I think real programms sometimes want to exit(1) in some
cases.
Christian