From 18d524a0d27c9cc66d8b5e8cf1fa79532e3e1313 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 2 Dec 2023 23:46:24 -0800 Subject: [PATCH] Avoid checking for out-of-gas on each 'andThen' Signed-off-by: Danila Fedorin --- src/Bergamot/Rules.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bergamot/Rules.elm b/src/Bergamot/Rules.elm index 8c0cb05..b31f13b 100644 --- a/src/Bergamot/Rules.elm +++ b/src/Bergamot/Rules.elm @@ -33,7 +33,7 @@ type alias Prover a = RuleEnv -> ProveState -> Search (a, ProveState) andThen : (a -> Prover b) -> Prover a -> Prover b andThen f p env ps = p env ps - |> Search.andThen (\(a, psp) -> if psp.gas > 0 then (f a) env psp else Search.fail) + |> Search.andThen (\(a, psp) -> (f a) env psp) join : Prover (Prover a) -> Prover a join p = andThen (\x -> x) p @@ -75,7 +75,7 @@ getUnificationState : Prover UnificationState getUnificationState env ps = Search.pure (ps.unificationState, ps) burn : Prover () -burn env ps = Search.pure ((), { ps | gas = ps.gas - 1}) +burn env ps = if ps.gas > 0 then Search.pure ((), { ps | gas = ps.gas - 1}) else Search.fail liftInstantiation : (a -> InstantiationState -> (b, InstantiationState)) -> a -> Prover b liftInstantiation f a env ps =