
I was trying to write my own equivalent to Don Stewart's mkcabal but ended up getting sidetracked. I made some generalised prompts for use at the command line and wanted to get some feedback on them. The full code can be found at [1] but the basic summary is like this:
prompt :: String -> IO String
Simple prompt - supply a question and receive the user's answer.
promptYesNo :: String -> Maybe String -> IO Bool
A yes/no question, with an optional value to ask about. I suppose this could be simplified to just one string.
promptList :: String -> [String] -> Maybe Integer -> IO Integer
Ask the user to choose from a list, where the result is the number chosen. The optional value is a default if the user doesn't pick a number.
promptListEdit :: String -> [String] -> Maybe Integer -> IO String
As above, but the last option in the list is an invitation to provide your own answer. Again the optional value is the default choice if nothing else is chosen. The result here is necessarily the string rather than the integer cos I didn't want to complicate matters further with stuff like Either types. If you can see any flaws or have any suggestions please let me know! Cheers, D. [1]: http://brokenhut.no-ip.org/~dougal/darcs/joincabal/CommandPrompts.hs

ithika:
I was trying to write my own equivalent to Don Stewart's mkcabal but ended up getting sidetracked. I made some generalised prompts for use at the command line and wanted to get some feedback on them.
The full code can be found at [1] but the basic summary is like this:
prompt :: String -> IO String
Simple prompt - supply a question and receive the user's answer.
promptYesNo :: String -> Maybe String -> IO Bool
A yes/no question, with an optional value to ask about. I suppose this could be simplified to just one string.
promptList :: String -> [String] -> Maybe Integer -> IO Integer
Ask the user to choose from a list, where the result is the number chosen. The optional value is a default if the user doesn't pick a number.
promptListEdit :: String -> [String] -> Maybe Integer -> IO String
As above, but the last option in the list is an invitation to provide your own answer. Again the optional value is the default choice if nothing else is chosen. The result here is necessarily the string rather than the integer cos I didn't want to complicate matters further with stuff like Either types.
If you can see any flaws or have any suggestions please let me know!
Looks pretty good, though you use case x :: Bool of True -> ... False -> ... when if x then ... else ... would be preferred. I wonder if there's a prompt API out there for python or something you could use for inspiration? -- Don

Dougal Stanton wrote:
I was trying to write my own equivalent to Don Stewart's mkcabal but ended up getting sidetracked. I made some generalised prompts for use at the command line and wanted to get some feedback on them.
The full code can be found at [1] but the basic summary is like this:
Hi, I also have a small module for use in a project I'm writing which I use for command line 'asking', you can find the code at : http://homepages.inf.ed.ac.uk/s9810217/software/fragments/Hask.hs and I guess it's possible something there might be of use to you. regards allan
participants (4)
-
Allan Clark
-
Antti-Juhani Kaijanaho
-
dons@cse.unsw.edu.au
-
Dougal Stanton