fail handled in the wrong monad
At least I think that's what's going on.


My main function looks like this:

            main :: IO ()
            main = do 
                putStrLn $ case eval testExpr of
                    Left msg -> "Error: " ++ msg
                    Right result -> show result

Where eval is (with some code removed):


            eval :: (Monad m) => Expr Float -> m Float
            eval (MultExpr "*" e1 e2) = evalBin (*) e1 e2
            eval (MultExpr "/" e1 e2) = evalBin (/) e1 e2
            eval (MultExpr _ _ _ ) = fail "Invalid operator. Expected * or /"


But, when `eval` fails, I get an error in IO, without the "Error: " string appended.
fail handled in the wrong monad
===

At least I think that's what's going on.


My main function looks like this:

            main :: IO ()
            main = do 
                putStrLn $ case eval testExpr of
                    Left msg -> "Error: " ++ msg
                    Right result -> show result

Where eval is (with some code removed):


            eval :: (Monad m) => Expr Float -> m Float
            eval (MultExpr "*" e1 e2) = evalBin (*) e1 e2
            eval (MultExpr "/" e1 e2) = evalBin (/) e1 e2
            eval (MultExpr _ _ _ ) = fail "Invalid operator. Expected * or /"


But, when `eval` fails, I get an error in IO, without the "Error: " string appended.