diff options
Diffstat (limited to 'src/Lib.hs')
-rw-r--r-- | src/Lib.hs | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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 |