August 2, 2012
readline is a Haskell binding to the GNU Readline library. It is now available in Fedora. Install it using:
$ sudo yum install ghc-readline-devel
The Readline library provides functions to for line editing, and managing history of commands entered interactively through the command-line. It is Free Software. A simple example of using ghc-readline is demonstrated:
import System.Console.Readline
readEvalPrintLoop :: IO ()
readEvalPrintLoop = do
maybeLine <- readline "% "
case maybeLine of
Nothing -> return ()
Just "exit" -> return ()
Just line -> do addHistory line
putStrLn $ "The user input: " ++ (show line)
readEvalPrintLoop
main = do
readEvalPrintLoop
Compile it using:
$ ghc --make read.hs
Linking read ...
Run it and test it:
$ ./read
%
The user input: ""
% Lorem ipsum
The user input: "Lorem ipsum"
% exit
$