looking for System.Console.Readline example

MartinNorbäck d95mback at dtek.chalmers.se
Tue Dec 2 14:40:29 EST 2003


tis 2003-12-02 klockan 14.23 skrev Johannes Waldmann:
> Martin Norbäck wrote:
> 
> > main = do input <- readline "prompt> " ; handle input
> 
> but this only reads one line (and it gives a Maybe String)
> I wanted a (lazy) list of all input lines,
> where the user should have the usual line editing functions available.

What do you mean? Readline is for editing one line. If you want
something like getting multiple lines until user presses ctrl-d or
something you can do this:

readlines :: IO [String]
readlines = do
  input <- readline ""
  case input of
    Nothing -> return []
    Just str -> do
      strs <- readlines
      return (str:strs)

It won't be lazy though.

Regards,
	Martin




More information about the Haskell mailing list