<div dir="ltr">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).<br>
<br>Alternatively change<br><br>result <- runEval env (eval (Plus (Var "x") (Lit 2)))<br><br>to<br><br>let result = runEval env (eval (Plus (Var "x") (Lit 2)))<br></div><div class="gmail_extra"><br>
<br><div class="gmail_quote">On Thu, Feb 20, 2014 at 7:19 PM, Mathew Phillips <span dir="ltr"><<a href="mailto:mathewrphillips@gmail.com" target="_blank">mathewrphillips@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">I have a module that looks like this<div><br></div><div>runEval :: (Show a) => Env -> Eval a -> Either String a</div><div>runEval = ...</div><div><br></div><div>data Value = IntVal Integer</div><div>

<br></div><div>main :: IO ()</div><div>main = do</div><div>    let env = Map.fromList [("x",IntVal 3)]</div><div>    result <- runEval env (eval (Plus (Var "x") (Lit 2)))</div><div>    case result of</div>

<div>        Left err -> putStrLn "Error: "++err</div><div>        Right (IntVal i) -> print i</div><div><br></div><div>when I call runEval from ghci I get back a result just fine </div><div><br></div><div>

let env = Map.fromList [("x",IntVal 3)]</div><div>runEval env (eval (Plus (Var "x") (Lit 2))) </div><div><br></div><div>This outputs <span style="font-family:arial">"Right (IntVal 5)" </span><span style="font-family:arial">as I would expect. </span><span style="font-family:arial">But when I try and compile my main method I get the following error.</span></div>

<div><br></div><div><div>Couldn't match expected type `Value'</div><div>with actual type `Either t1 Value'</div><div>    In the pattern: Right (IntVal i)</div><div>    In a case alternative: Right (IntVal i) -> print i</div>

<div>    In a stmt of a 'do' block:</div><div>      case result of {</div><div>        Left err -> print err</div><div>        Right (IntVal i) -> print i }</div></div><div><br></div><div>I also tried using (putStrLn . either show show) result, but this gave me the following error. </div>

<div><br></div><div><div>Couldn't match expected type `Either a0 b0'</div><div>with actual type `Value'</div><div>    In the first argument of `putStrLn . either show show', namely</div><div>      `result'</div>

<div>    In a stmt of a 'do' block: (putStrLn . either show show) result</div><div>    In the expression:</div><div>      do { let env = Map.fromList ...;</div><div>           result <- runEval3 env (eval3 (Plus (Var "x") (Lit 2)));</div>

<div>           (putStrLn . either show show) result }</div></div><div><br></div><div>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"?</div>

<div><br></div><div>Matt P.</div><div><br></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>