aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Eval.hs
diff options
context:
space:
mode:
authorMarvin Borner2023-11-11 19:15:36 +0100
committerMarvin Borner2023-11-11 19:15:44 +0100
commit91db2d7825f3d820d9c7e3e862148411de0897b9 (patch)
tree5701a975f638d19f50ac39022687c838569fad43 /src/Eval.hs
parenteda9bdd118d8d115cbd7d88e449dde465bb4894a (diff)
Fixed unquote operator
Diffstat (limited to 'src/Eval.hs')
-rw-r--r--src/Eval.hs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/Eval.hs b/src/Eval.hs
index 223a43a..426b733 100644
--- a/src/Eval.hs
+++ b/src/Eval.hs
@@ -134,15 +134,16 @@ evalPrefix p e = evalExp $ Application (Function p) e
evalQuote :: Expression -> Environment -> EvalState (Failable Expression)
evalQuote f sub = evalExp f sub >>= \case
Left e -> pure $ Left e
- Right f' -> pure $ Right $ quotify f'
+ Right f' -> pure $ Right $ quotify 0 f'
where
base l r = Abstraction $ Abstraction $ Abstraction $ Application l r
- quotify (Abstraction e) = base (Bruijn 0) (quotify e)
- quotify (Application l r) =
- base (Application (Bruijn 1) (quotify l)) (quotify r)
- quotify (Bruijn i) = base (Bruijn 2) (decimalToUnary $ fromIntegral i)
- quotify (Unquote e) = quotify e
- quotify _ = invalidProgramState
+ quotify n (Abstraction e) = base (Bruijn 0) (quotify (n + 1) e)
+ quotify n (Application l r) =
+ base (Application (Bruijn 1) (quotify (n + 1) l)) (quotify (n + 1) r)
+ quotify _ (Bruijn i) = base (Bruijn 2) (decimalToUnary $ fromIntegral i)
+ quotify n (Unquote (Bruijn i)) = Bruijn $ n * 3 + i
+ quotify n (Unquote e ) = quotify n e
+ quotify _ _ = invalidProgramState
evalUnquote :: Expression -> Environment -> EvalState (Failable Expression)
evalUnquote f sub = evalExp f sub >>= \case