Because you didn't put all your code, I'm not sure if this is correct, but my best guess is that you expect runEval to return Either String a, but the way you are using it I suspect you actually want its type to be IO (Either String a).
Alternatively changeto
result <- runEval env (eval (Plus (Var "x") (Lit 2)))
let result = runEval env (eval (Plus (Var "x") (Lit 2)))
On Thu, Feb 20, 2014 at 7:19 PM, Mathew Phillips <mathewrphillips@gmail.com> wrote:
_______________________________________________I have a module that looks like thisrunEval :: (Show a) => Env -> Eval a -> Either String arunEval = ...data Value = IntVal Integermain :: IO ()main = dolet env = Map.fromList [("x",IntVal 3)]result <- runEval env (eval (Plus (Var "x") (Lit 2)))case result ofLeft err -> putStrLn "Error: "++errRight (IntVal i) -> print iwhen I call runEval from ghci I get back a result just finelet env = Map.fromList [("x",IntVal 3)]runEval env (eval (Plus (Var "x") (Lit 2)))This outputs "Right (IntVal 5)" as I would expect. But when I try and compile my main method I get the following error.Couldn't match expected type `Value'with actual type `Either t1 Value'In the pattern: Right (IntVal i)In a case alternative: Right (IntVal i) -> print iIn a stmt of a 'do' block:case result of {Left err -> print errRight (IntVal i) -> print i }I also tried using (putStrLn . either show show) result, but this gave me the following error.Couldn't match expected type `Either a0 b0'with actual type `Value'In the first argument of `putStrLn . either show show', namely`result'In a stmt of a 'do' block: (putStrLn . either show show) resultIn the expression:do { let env = Map.fromList ...;result <- runEval3 env (eval3 (Plus (Var "x") (Lit 2)));(putStrLn . either show show) result }Why is it when I try and pattern match on Either String Value it says result is of type "Value", but when I try and use either it says result is of type "Either String Value"?Matt P.
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners