[Haskell-cafe] Re: implementing recursive let

Ben Franksen ben.franksen at online.de
Thu Nov 26 12:35:53 EST 2009


Ben Franksen wrote:
> My problem is that I still don't understand why this is so! I know of
> course that pattern matching is strict, but I thought this should be ok
> here, since I evaluate the declarations _before_ the body, so when
> evaluation of the body demands the variable, it will be defined.

Another data point: It /has/ something to do with ErrorT. If I remove the
ErrorT from the monad stack it works, even with the pattern matching in the
variable lookup:

newtype Eval a = Eval {
    unEval :: {- ErrorT String -} (StateT Env (Writer [String])) a
  } deriving (
    Monad,
    MonadFix,
    MonadWriter [String], -- for warnings & other messages
    MonadState Env{- ,
    MonadError String -}
  )

runEval :: Eval Value -> {- Either String -} Value
runEval = fst . runWriter . flip evalStateT M.empty . {- runErrorT . -}
unEval

*Main> evaluate example 
1

I am still lost as to how to make this work with ErrorT.

Cheers
Ben



More information about the Haskell-Cafe mailing list