Given the proof of concept code below, I would like to somehow execute my foo function with the ability to output a Paul! string Paul! and the ability to get its return value inside the InputT monad transformer without using unsafePerformIO to remove the IO wrapper after runExceptT .
import Control.Monad.Except import System.IO.Unsafe (unsafePerformIO) import System.Console.Haskeline type ErrorWithIO = ExceptT String IO foo :: String -> ErrorWithIO String foo "paul" = do liftIO $ putStrLn "Paul!" return "OK!" foo _ = throwError "ERROR!" runRepl :: IO () runRepl = runInputT defaultSettings $ loop loop :: InputT IO () loop = do line <- getInputLine "> " case line of Nothing -> return () Just input -> do return $ putStrLn "asd" case unsafePerformIO $ runExceptT $ foo input of Left err -> outputStrLn err >> loop Right res -> do x <- outputStrLn . show $ res loop main :: IO () main = runRepl >> putStrLn "Goodbye!"
Did I miss something obvious here?
source share