[Haskell-cafe] Command line prompt templates
ithika at gmail.com
Thu Nov 23 20:18:53 EST 2006
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  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
> 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!
More information about the Haskell-Cafe