A REPL(Read–eval–print loop) is a indispensable tool for a programming language.
In a REPL, the user enters one or more expressions (rather than an entire compilation unit), which are then evaluated, and the results displayed.
However, writing a good quality REPL is not trivial because it often requires complicated features. Some of the functionality provided by a REPL includes:
- History of inputs and outputs.
- Input editing and context specific completion over symbols, pathnames, class names and other objects.
In Haskell, we have the haskeline package which provides exactly these two features.
Haskeline provides a user interface for line input in command-line programs. This library is similar in purpose to readline, but since it is written in Haskell it is (hopefully) more easily used in other Haskell programs.
Haskeline provides a monad transformer, InputT. You can perform input and output with getInputLine and outputStrLn which are Unicode-aware. But you can also perform any IO action you want with liftIO.
I’ve just written a decent REPL for my scheme interpreter with Haskeline.