aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Lib.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Lib.hs')
-rw-r--r--src/Lib.hs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/Lib.hs b/src/Lib.hs
index 4f4d2f3..5d58008 100644
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -5,6 +5,7 @@ module Lib
) where
import Term
+import Utils
data State = L | R
@@ -17,13 +18,22 @@ k = Abs (Abs (Idx 1))
i :: Term
i = Abs (Idx 0)
+clean :: String -> String
+clean (x : xs) | x == '0' || x == '1' = x : clean xs
+ | otherwise = clean xs
+clean [] = []
+
-- reverse wouldn't be needed if [0F] instead of [F0]
-fromJotter :: String -> Term
-fromJotter = go L . reverse
+fromCleanJotter :: String -> Term
+fromCleanJotter t | even $ length t = go L $ reverse t
+ | otherwise = go R $ reverse t
where
go L ('0' : xs) = App s (go R xs)
go R ('0' : xs) = App (go L xs) s
go L ('1' : xs) = App k (go R xs)
go R ('1' : xs) = App (go L xs) k
- go d (_ : xs) = go d xs
go _ [] = i
+ go _ _ = invalid
+
+fromJotter :: String -> Term
+fromJotter = fromCleanJotter . clean