I came across the same problem, but maybe I can give a little more context in what is happening for my situation, and maybe this can help.
Creating an interpreter using typedef:
interp :: Env -> Expr -> M Val
which processes loops in this format:
for ( var = expr to expr ) ( expr )
The data constructor is defined as follows:
data Val =
ValInt Int
| ValBool Bool
| ValFun (Val -> M Val)
| ValRecFun (Val -> Val -> M Val)
| ValRef Loc
| ValNil
And an extended environment defined as:
extendEnv :: Identifier -> Val -> Env -> Env
extendEnv var val (Env bs) = Env ((var,val):bs)
Here where I am:
interp env (For x e1 e2 e3) = do
(ValInt v1) <- interp env e1
(ValInt v2) <- interp env e2
if (v1 < v2)
then
let nenv = extendEnv x e1 env in do
interp nenv e3
interp env (For x e1 e2 e3)
else return ValNil
Obviously, I don’t want to pass “e1” to the recursive call of the for loop, but rather, the evaluated variable “v1” is incremented ... but I cannot figure out how to pass the correct expression “v1” to it. Is this enough to help a little? :)
* UPDATE *
, doLoop, . , , , "env" doLoop, .
interp env (For x e1 e2 e3)= do
(ValInt v1) <- interp env e1
(ValInt v2) <- interp env e2
return doLoop x v1 v2 env e3
doLoop :: Identifier -> Int -> Int -> Env-> Expr -> M Val
doLoop x v1 v2 env e3 =
if v1 > v2 then return ValNil
else
let nenv = extendEnv x (ValInt v1) env in
interp nenv e3
doLoop x (ValInt (v1+1)) v2 nenv e3
UPDATE
, , :
return doLoop x v1 v2 env e3
M Val' against my inferred type Expr → M Val '.
- ?