
Hi, Attached is a patch that adds a :main command to hugs. :main arguments is equivalent to arguments `withArgs` main, but easier to use because you don't need to import anything extra, and the arguments are parsed as if they were arguments - i.e. :main my test "of this", instead of ["my","test","of this"] `withArgs` main. Since i don't know a whole lot about this area of the compiler, and it is changing the user interface for everyone, I thought it best that someone checks its at least sane before i do anything with it. Thanks Neil

On Sun, Oct 30, 2005 at 12:40:47PM +0000, Neil Mitchell wrote:
Attached is a patch that adds a :main command to hugs. :main arguments is equivalent to arguments `withArgs` main, but easier to use because you don't need to import anything extra, and the arguments are parsed as if they were arguments - i.e. :main my test "of this", instead of ["my","test","of this"] `withArgs` main.
Well the Main module probably imports System.Environment anyway, but I guess this is harmless, and presumably this will be used by some WinHugs thing. The usual way to parse arguments to Hugs commands is readFilename(), which also allows backslashed quotes. Using this would aid consistency, but you'll need to work around the fact that it returns a string in static storage.

Well the Main module probably imports System.Environment anyway Mine never does, I always import System, which doesn't include withArgs
I guess this is harmless, and presumably this will be used by some WinHugs thing. Indeed :)
The usual way to parse arguments to Hugs commands is readFilename(), That does make it much easier, and much shorter, attached is a new version. If no one has any objections I'll check it in.
Thanks Neil

On Sun, Oct 30, 2005 at 02:07:30PM +0000, Neil Mitchell wrote:
Well the Main module probably imports System.Environment anyway Mine never does, I always import System, which doesn't include withArgs
Haskell 98 libraries? How quaint.
The usual way to parse arguments to Hugs commands is readFilename(), That does make it much easier, and much shorter, attached is a new version. If no one has any objections I'll check it in.
This differs from setArgs in that it leave the args set. Maybe the command should just set the args.

Haskell 98 libraries? How quaint. Up until I started working on WinHugs, I was using a 2001 release of WinHugs, which didn't really work with much beyond Haskell 98 libraries...
This differs from setArgs in that it leave the args set. Maybe the command should just set the args.
From what I can tell, setArgs leaves the arguments set, but withArgs doesn't because with changes the arguments back after the computation has run. My initial thought was to revert the arguments back afterwards, but it wasn't immediately clear how to do this - because of things like longjmp.

On Sun, Oct 30, 2005 at 07:59:16PM +0000, Neil Mitchell wrote:
This differs from setArgs in that it leave the args set. Maybe the command should just set the args.
From what I can tell, setArgs leaves the arguments set, but withArgs doesn't because with changes the arguments back after the computation has run. My initial thought was to revert the arguments back afterwards, but it wasn't immediately clear how to do this - because of things like longjmp.
Sorry, I meant withArgs -- setArgs is internal. But instead of resetting, how about making setting the args the whole function of the new command, so then they can run main (or anything else) several times with the same argument? (I'm not sure what WinHugs interface you had in mind.)

Sorry, I meant withArgs -- setArgs is internal. But instead of resetting, how about making setting the args the whole function of the new command, so then they can run main (or anything else) several times with the same argument?
This is mainly motivated by my recent development work - I kept ending up with a function called main2 which is called by main with the arguments, so I could develop it more easily. A :main removes this need, if only :args was available then it would require twice as many commands, i.e. :args blah, main, if you were continually changing the arguments. Also, this way main more closely models the Clean approach, where command line arguments are passed into main, not in a monad. However, having :args as well might be quite handy.
(I'm not sure what WinHugs interface you had in mind.) Currently the run button when the user has typed no expression runs 'main', I intend to change this to ':main'
Thanks Neil

However, having :args as well might be quite handy. In GHCi this feature is available as :set args blah, not sure if thats a good way to go or not.
Shall I commit :main then? Or should I save it as a WinHugs specific feature? Thanks Neil
(I'm not sure what WinHugs interface you had in mind.) Currently the run button when the user has typed no expression runs 'main', I intend to change this to ':main'
Thanks
Neil

On Thu, Nov 10, 2005 at 01:22:24PM +0000, Neil Mitchell wrote:
However, having :args as well might be quite handy. In GHCi this feature is available as :set args blah, not sure if thats a good way to go or not.
Will WinHugs have something equivalent, for the situation where one wants to run the program again with the same args after each change?
Shall I commit :main then? Or should I save it as a WinHugs specific feature?
Having :main would break the Hugs rule that all commands can be abbreviated to a single letter. :Main?

On 11/10/05, Ross Paterson
On Thu, Nov 10, 2005 at 01:22:24PM +0000, Neil Mitchell wrote:
However, having :args as well might be quite handy. In GHCi this feature is available as :set args blah, not sure if thats a good way to go or not.
Will WinHugs have something equivalent, for the situation where one wants to run the program again with the same args after each change?
Yes, it has full command history, so the up arrow does this perfectly. I'm not sure people need anything else, but it can be done if they do.
Shall I commit :main then? Or should I save it as a WinHugs specific feature?
Having :main would break the Hugs rule that all commands can be abbreviated to a single letter. :Main?
main is basically calling main, and in Haskell Main would be something entirely different. However, the single letter rule is useful. Not sure on that one. Neil

Hi
Having :main would break the Hugs rule that all commands can be abbreviated to a single letter. :Main?
main is basically calling main, and in Haskell Main would be something entirely different. However, the single letter rule is useful. Not sure on that one.
I still have this floating around - I personally find the :main command indispensable now, and curse when I get to a computer without it (or have to use GHCi, again loosing :main). I will probably post it as a recommendation to the GHC team as soon as its in hugs. Any final thoughts on whether it should go in or not, and what its name should be? Thanks Neil

On Tue, Jan 10, 2006 at 01:53:24AM +0000, Neil Mitchell wrote:
Having :main would break the Hugs rule that all commands can be abbreviated to a single letter. :Main?
main is basically calling main, and in Haskell Main would be something entirely different. However, the single letter rule is useful. Not sure on that one.
I still have this floating around - I personally find the :main command indispensable now, and curse when I get to a computer without it (or have to use GHCi, again loosing :main). I will probably post it as a recommendation to the GHC team as soon as its in hugs.
Any final thoughts on whether it should go in or not, and what its name should be?
Might as put :main in, as long as :m still abbreviates :module. Don't forget to update the User's Guide too.

Might as put :main in, as long as :m still abbreviates :module. Committed, :m is still module.
Don't forget to update the User's Guide too. Attached is a patch which updates the user guide. I couldn't get the user guide to build at all (docbook seems way to complicated for me), so I can't test that this doesn't break the userguide. I'm also not familiar with the docbook conventions/commands so I would appreciate someone checking that this is correct.
Thanks Neil
participants (2)
-
Neil Mitchell
-
Ross Paterson