
On Sun, Jul 31, 2016 at 06:44:14PM +0000, Ramnath R Iyer wrote:
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:
1. What would be a sensible type signature for X?
Hello Ramnath, as now evaluate *has to* return a String because you pass its output as an argument to outputStrLn (which has a ~ `String -> InputT IO ()` signature itself). A quick hack is for `evaluate` to return evaluate :: String -> (String, Bool) where the Bool stands for 'should I exit or not' (using a datatype and/or a type synonym would be better and more clear). You can then write let (s, b) = evaluate input outputStrLn $ "Something " ++ s if b then loop else exit Your code has a very distinct imperative flavour (there are ways to get rid of that case/if cascade), but my opinion is: first make it work, then make it pretty. Does that help? -F