From f6dde1041a52da4f2e7ccb77eed3c577f9d07798 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Wed, 1 Apr 2026 16:18:01 +0200 Subject: Remove answers from sent challenges Also fix integration test --- lambda-calcul/haskell/src/Minilang/Lambda.hs | 78 ++++++++++++++-------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'lambda-calcul/haskell/src/Minilang/Lambda.hs') diff --git a/lambda-calcul/haskell/src/Minilang/Lambda.hs b/lambda-calcul/haskell/src/Minilang/Lambda.hs index fbaf35d..82ab8bf 100644 --- a/lambda-calcul/haskell/src/Minilang/Lambda.hs +++ b/lambda-calcul/haskell/src/Minilang/Lambda.hs @@ -19,46 +19,46 @@ loadProgram :: Env -> Context -> [AST] -> - Either TypeError ([(Term, Type)], Env, Context) + Either TypeError ([(Term, Maybe Type)], Env, Context) loadProgram evaluator language env context exprs = fmap (\(res, e, c) -> (reverse res, e, c)) result - where - result = - foldl - ( \acc expr -> - case acc of - Left typeError -> Left typeError - Right (results, env', context') -> - case runExpr language expr env' context' of - Left typeError -> Left typeError - Right (Nothing, env'', context'') -> - Right (results, env'', context'') - Right (Just res, env'', context'') -> - Right (res : results, env'', context'') - ) - (Right ([], env, context)) - exprs - - runExpr language (Def ident body) env context = - let term = evalInEnvWith evaluator env body - in case language of - Typed -> - case infer term of + where + result = + foldl + ( \acc expr -> + case acc of + Left typeError -> Left typeError + Right (results, env', context') -> + case runExpr expr env' context' of Left typeError -> Left typeError - Right typ -> - Right (Nothing, (ident, term) : env, extendContext ident typ context) - Untyped -> - Right (Nothing, (ident, term) : env, context) - runExpr language expr env context = - let v = evalInEnvWith evaluator env expr - in case language of - Typed -> - case infer v of - Left typeError -> Left typeError - Right typ -> - Right (Just (v, typ), env, context) - Untyped -> - Right (Just (v, TyVar ""), env, context) + Right (Nothing, env'', context'') -> + Right (results, env'', context'') + Right (Just res, env'', context'') -> + Right (res : results, env'', context'') + ) + (Right ([], env, context)) + exprs + + runExpr (Def ident body) env' context' = + let term = evalInEnvWith evaluator env' body + in case language of + Typed -> + case infer term of + Left typeError -> Left typeError + Right typ -> + Right (Nothing, (ident, term) : env', extendContext ident typ context') + Untyped -> + Right (Nothing, (ident, term) : env', context') + runExpr expr env' context' = + let v = evalInEnvWith evaluator env' expr + in case language of + Typed -> + case infer v of + Left typeError -> Left typeError + Right typ -> + Right (Just (v, Just typ), env', context') + Untyped -> + Right (Just (v, Nothing), env', context') -- | Evaluate an 'AST' in the given 'Env' using the De Bruijn CBV evaluator. -- This is the default evaluator used by the server and REPL. @@ -74,11 +74,11 @@ evalInEnvWith DeBruijn env expr = env' = (second toDeBruijn <$> env) ++ builtinDeBruijnEnv in fromDeBruijn $ eval' env' (toDeBruijn term) evalInEnvWith NbE env expr = - let term = desugar expr + let term = desugar expr -- Build an EnvValue from the user Env by evaluating each binding's -- Term in the accumulated value env (builtins always available at the -- bottom). foldl builds left-to-right so earlier bindings are visible -- when evaluating later ones. - envV = foldl addBinding builtinEnvValue env + envV = foldl addBinding builtinEnvValue env addBinding acc (name, t) = (name, Eval.eval acc t) : acc in Eval.readBack (Eval.eval envV term) -- cgit v1.3.1