diff options
author | Marvin Borner | 2024-02-16 16:22:12 +0100 |
---|---|---|
committer | Marvin Borner | 2024-02-16 16:22:12 +0100 |
commit | a852b3e28f7f080c1912e9a7c07cb85636bce89a (patch) | |
tree | c196fdb9e51d15d797954a48c61cdf4fbed14b67 /src/Helper.hs | |
parent | c7801f7c1e5e9ca1dee061f011492ba37e0e1c73 (diff) |
Added meta humanifier
Diffstat (limited to 'src/Helper.hs')
-rw-r--r-- | src/Helper.hs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Helper.hs b/src/Helper.hs index b1dc5f6..4500de6 100644 --- a/src/Helper.hs +++ b/src/Helper.hs @@ -317,10 +317,22 @@ maybeHumanifyExpression e = <|> ternaryToDecimal e <|> humanifyList e <|> humanifyPair e + <|> humanifyMeta e humanifyExpression :: Expression -> String humanifyExpression e = fromMaybe "" (maybeHumanifyExpression e) +humanifyMeta :: Expression -> Maybe String +humanifyMeta e = ("`" <>) <$> go e + where + go (Abstraction (Abstraction (Abstraction (Application (Bruijn 0) t)))) = + go t >>= (\a -> pure $ "[" <> a <> "]") + go (Abstraction (Abstraction (Abstraction (Application (Application (Bruijn 1) a) b)))) + = go a >>= \l -> go b >>= \r -> pure $ "(" <> l <> " " <> r <> ")" + go (Abstraction (Abstraction (Abstraction (Application (Bruijn 2) n)))) = + unaryToDecimal' n + go _ = Nothing + humanifyList :: Expression -> Maybe String humanifyList e = do es <- unlistify e @@ -372,9 +384,12 @@ decimalToDeBruijn n | n < 0 = decimalToDeBruijn 0 gen n' = Abstraction $ gen (n' - 1) unaryToDecimal :: Expression -> Maybe String -unaryToDecimal e = do +unaryToDecimal e = (<> "u") <$> unaryToDecimal' e + +unaryToDecimal' :: Expression -> Maybe String +unaryToDecimal' e = do res <- resolve e - return $ show (sum res :: Integer) <> "u" + return $ show (sum res :: Integer) where multiplier (Bruijn 1) = Just 1 multiplier _ = Nothing |