aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Helper.hs
diff options
context:
space:
mode:
authorMarvin Borner2023-08-25 13:39:04 +0200
committerMarvin Borner2023-09-03 17:18:44 +0200
commit1f985159c3ca5d15a2229a495b2c15a5a1af2dd6 (patch)
tree090a2bee24f169ebafb311199b3ba6838b3f1ac5 /src/Helper.hs
parent06002dd74add24ece55453088e3df0f6c37f0105 (diff)
Added De Bruijn numerals
Diffstat (limited to 'src/Helper.hs')
-rw-r--r--src/Helper.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Helper.hs b/src/Helper.hs
index 2b2e31c..f760597 100644
--- a/src/Helper.hs
+++ b/src/Helper.hs
@@ -328,6 +328,14 @@ decimalToUnary n | n < 0 = decimalToUnary 0
gen 0 = Bruijn 0
gen n' = Application (Bruijn 1) (gen (n' - 1))
+-- Decimal to De Bruijn encoding
+decimalToDeBruijn :: Integer -> Expression
+decimalToDeBruijn n | n < 0 = decimalToDeBruijn 0
+ | otherwise = gen n
+ where
+ gen 0 = Abstraction $ Bruijn $ fromInteger n
+ gen n' = Abstraction $ gen (n' - 1)
+
unaryToDecimal :: Expression -> Maybe String
unaryToDecimal e = do
res <- resolve e