In your hpaste, you have the appVals function, which has been renamed eppVals in the above question. It's useless.
Let's look at some types:
epp :: Exp -> Error ValappVals :: Val -> Val -> Error Val
Error message Failed to match the expected Val type with the actual Error Val type, which is trying to tell you that the first parameter appVals must be of type Val (see type label for appVals ), but with the actual type of value that you provided as the first parameter, is v1 , defined as epp e1 , which is of type Error Val (see type signature for epp ).
Val and Error Val not of the same type. It's your problem.
How to fix it? You need to somehow handle the error cases separately from the rest of the calculations. If you have implemented Applicative or Monad classes for your Error type, this is almost certainly what they do.
Edit: You do not include the definition of your Error , but I expect it to look like this:
data Error a = S a | Error String
Run a few classes for it (you need import Control.Applicative ):
instance Functor Error where fmap f (S x) = S (fx) fmap _ (Error s) = Error s instance Applicative Error where pure = S Error s <*> _ = Error s _ <*> Error s = Error s S f <*> S x = S (fx)
Now you can rewrite
epp (App e1 e2) = eppVals <$> epp e1 <*> epp e2
source share