<div dir="ltr"><div><font color="#757575">Hi all,</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">I'm trying to write a fairly simple program to understand Haskell in practice. I am implementing a simple REPL where I can write some text, and that text can be parsed into a command with arguments. Then, I would like to be able to turn this into a 'plugin' system of sorts, with a module/logic per command.</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">I understand the Text.Parsec library may already provide these things out of the box, but for now, I would prefer to reinvent the wheel.</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">The program below is what I have working right now (very trivial). I want to modify this program, so that the `evaluate input` returns not a String, but a type X that includes information on whether to "continue" and show a prompt after rendering the result, or exit altogether. So the specific questions I have here are:</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">1. What would be a sensible type signature for X?</font></div><div><font color="#757575">2. Assuming X to exist, what is the right way to modify main to use it? My current intuition is to modify the outputStrLn ... loop statements to include an if-then-else, but I'm not sure what the right modification is (all my attempts seemed like imperative programming and failed compilation unsurprisingly).</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">import Evaluator</font></div><div><font color="#757575">import System.Console.Haskeline</font></div><div><font color="#757575"><br></font></div><div><font color="#757575">main :: IO ()</font></div><div><font color="#757575">main = runInputT defaultSettings loop</font></div><div><font color="#757575">  where</font></div><div><font color="#757575">    loop :: InputT IO ()</font></div><div><font color="#757575">    loop = do</font></div><div><font color="#757575">      line <- getInputLine ">> "</font></div><div><font color="#757575">      case line of</font></div><div><font color="#757575">        Nothing     -> return ()</font></div><div><font color="#757575">        Just "quit" -> return ()</font></div><div><font color="#757575">        Just input  -> do</font></div><div><font color="#757575">          outputStrLn $ "Executing: " ++ (evaluate input)</font></div><div><font color="#757575">          loop</font></div><div><font color="#757575"><br></font></div><div><font color="#757575"><div>module Evaluator where</div><div><br></div><div>evaluate :: String -> String</div><div>evaluate value = value</div></font></div></div>