self eval fix: return oracle result without recursion

This commit is contained in:
ProgramSnail 2025-10-26 20:38:40 +03:00
parent 482b41680e
commit 0270c44bf6

View file

@ -203,21 +203,21 @@ eval conf (CreateLeafE e) = do v <- eval conf e
return $ TreeV $ TLeaf v return $ TreeV $ TLeaf v
eval conf (IfE {ifCond, ifDoThen, ifDoElse}) = do BoolV condB <- eval conf ifCond eval conf (IfE {ifCond, ifDoThen, ifDoElse}) = do BoolV condB <- eval conf ifCond
if condB then eval conf ifDoThen else eval conf ifDoElse if condB then eval conf ifDoThen else eval conf ifDoElse
eval conf (SelfE e) = do ListV newInput <- eval conf e eval conf (SelfE e) = do ListV recInput <- eval conf e
-- NOTE: replaced guards for better errors description -- NOTE: replaced guards for better errors description
-- guard $ length newInput == length (confInput conf) -- guard $ length newInput == length (confInput conf)
-- guard $ and $ zipWith structuralLess newInput (confInput conf) -- guard $ and $ zipWith structuralLess newInput (confInput conf)
if length newInput /= length (confInput conf) if length recInput /= length (confInput conf)
then RecError $ "self call different length, new=" ++ show newInput ++ " old=" ++ show (confInput conf) then RecError $ "self call different length, new=" ++ show recInput ++ " old=" ++ show (confInput conf)
else do else do
if not $ and $ zipWith structuralLess newInput (confInput conf) if not $ and $ zipWith structuralLess recInput (confInput conf)
then RecError $ "self call on >= exprs, new=" ++ show newInput ++ " old=" ++ show (confInput conf) then RecError $ "self call on >= exprs, new=" ++ show recInput ++ " old=" ++ show (confInput conf)
else do else do
if newInput `notElem` confExamples conf then case confOracle conf recInput of
(case confOracle conf newInput of Just recOutput -> if recInput `elem` confExamples conf
Just expectedV -> NewExamples [(newInput, expectedV)] then return recOutput
Nothing -> RecError $ "no oracle output on " ++ show newInput) -- TODO: ??? else NewExamples [(recInput, recOutput)]
else eval conf{ confInput = newInput } (confProg conf) Nothing -> RecError $ "no oracle output on " ++ show recInput
eval conf (InputE e) = do IntV i <- eval conf e eval conf (InputE e) = do IntV i <- eval conf e
if i < 0 || i >= length (confInput conf) -- NOTE: replaced guard for better errors description if i < 0 || i >= length (confInput conf) -- NOTE: replaced guard for better errors description
then FatalError $ "can't access input " ++ show (confInput conf) ++ " by id " ++ show i then FatalError $ "can't access input " ++ show (confInput conf) ++ " by id " ++ show i