[Haskell-cafe] Terminal-like Application Design

allan a.d.clark at ed.ac.uk
Fri Oct 17 04:35:01 EDT 2008


Hi Jeff

It sounds like maybe you just want an application that works a bit like 'cabal'.
So with cabal the first argument is taken as the 'command' and then the rest are based on that:

cabal build --some other --options --which may --or --may --not have --arguments

Yi has a simple template for a script which should get you started, please find it attached.

So here instead of processOptions, you might want, processCommand

processCommand :: [ String ] -> IO ()
processCommand ("build" : args) = processBuildCommand args
processCommand ("play" : args)  = processPlayCommand args
processCommand []               = putStrLn "You must supply a command"
processCommand _                = putStrLn "Sorry I don't understand your command" --Probably out put help here as well

processBuildCommand :: [ String ] -> IO ()
processBuildCommand = similar to the processOptions except now you are sure you are in a 'build' command

you *might* even have a separate set of option descreptions for each command.

hth
allan




Jeff Wheeler wrote:
> Hi,
> 
> I'm a slight Haskell newbie, but I'm trying to write a terminal-like
> application that accepts simple commands with optional arguments, and
> can then execute them. Most of these commands will need IO, as later I
> will want to communicate over USB for most of them.
> 
> I was hoping, though, that I could get some comments on the initial
> architecture I've been playing with [1].
> 
> I suspect I should be using some sort of monad to represent the
> commands, but I don't fully understand monads, and am not sure how it
> would apply in this context.
> 
> Should I be using a monad here, and if so, how?
> 
> Thanks in advance,
> Jeff Wheeler
> 
> [1] http://media.nokrev.com/junk/cli/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 


-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Script.hs
Type: text/x-haskell
Size: 1800 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081017/79a3c28e/Script.bin


More information about the Haskell-Cafe mailing list