phino 0.0.167 → 0.0.168
raw patch · 20 files changed
+378/−131 lines, 20 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Sodg: Terminated :: Text -> SodgException
+ Pointer: identical :: a -> a -> Bool
+ Sodg: Terminator :: Int -> Command
Files
- README.md +2/−2
- phino.cabal +2/−1
- src/AST.hs +56/−35
- src/CLI/Helpers.hs +1/−1
- src/Morph.hs +57/−55
- src/Pointer.hs +13/−0
- src/Replacer.hs +4/−1
- src/Sides.hs +33/−21
- src/Sodg.hs +4/−5
- test-resources/rewriter-packs/custom/applies-a-match-equal-to-one-swallowed-beside-an-inert-term.yaml +15/−0
- test-resources/sodg-packs/bottom-alone.yaml +7/−0
- test-resources/sodg-packs/bottom-argument.yaml +6/−1
- test-resources/sodg-packs/bottom-dispatch.yaml +13/−0
- test-resources/sodg-packs/bottom.yaml +6/−1
- test/ASTSpec.hs +26/−1
- test/CLISpec.hs +65/−2
- test/MorphSpec.hs +37/−2
- test/ReplacerSpec.hs +12/−0
- test/SidesSpec.hs +15/−2
- test/SodgSpec.hs +4/−1
README.md view
@@ -34,7 +34,7 @@ ```bash cabal update-cabal install --overwrite-policy=always phino-0.0.166+cabal install --overwrite-policy=always phino-0.0.167 phino --version ``` @@ -59,7 +59,7 @@ for the runner and puts it on the `PATH`: ```yaml-- uses: objectionary/phino@0.0.166+- uses: objectionary/phino@0.0.167 with: version-file: phino-version.txt - run: phino --version
phino.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: phino-version: 0.0.167+version: 0.0.168 license: MIT synopsis: Command-Line Manipulator of 𝜑-Calculus Expressions description: Please see the README on GitHub at <https://github.com/objectionary/phino#readme>@@ -82,6 +82,7 @@ Morph Must Parser+ Pointer Printer Random Regexp
src/AST.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE LambdaCase #-}-{-# LANGUAGE MagicHash #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-}@@ -54,13 +53,14 @@ import Data.Bits (xor) import qualified Data.IntMap.Strict as IntMap+import qualified Data.IntSet as IntSet import qualified Data.List as List import qualified Data.Map.Strict as Map import Data.Maybe (fromMaybe, isJust, isNothing, listToMaybe) import Data.Text (Text) import qualified Data.Text as T-import GHC.Exts (isTrue#, reallyUnsafePtrEquality#) import GHC.Generics (Generic)+import Pointer (identical) data Slot = Slot Text Int deriving (Eq, Ord, Show)@@ -78,7 +78,7 @@ | ExPhiAgain (Maybe String) Int Expression | ExBytes Bytes -data Facts = Facts !Int !Int !Bool !Bool+data Facts = Facts !Int Int !Int !Bool !Bool {-# COMPLETE ExFormation, ExXi, ExRoot, ExTermination, ExApplication, ExDispatch, ExMeta, ExAny, ExPhiMeet, ExPhiAgain, ExBytes #-} @@ -122,10 +122,10 @@ known term = established term established :: Expression -> Facts-established term = Facts (layer id hashExpression term) (tally term) (calm term) (unrepeated term)+established term = Facts (layer id hashExpression term) (layer (const 0) hashShape term) (tally term) (calm term) (unrepeated term) instance Eq Expression where- left == right = left `seq` right `seq` (isTrue# (reallyUnsafePtrEquality# left right) || congruent left right)+ left == right = identical left right || congruent left right where congruent :: Expression -> Expression -> Bool congruent (Formed facts bds) (Formed facts' bds') = alongside facts facts' && bds == bds'@@ -141,19 +141,23 @@ congruent (ExBytes bts) (ExBytes bts') = bts == bts' congruent _ _ = False alongside :: Facts -> Facts -> Bool- alongside (Facts digest _ _ _) (Facts digest' _ _ _) = digest == digest'+ alongside (Facts digest _ _ _ _) (Facts digest' _ _ _ _) = digest == digest' instance Ord Expression where- compare (ExFormation bds) (ExFormation bds') = compare bds bds'- compare (ExApplication expr arg) (ExApplication expr' arg') = compare expr expr' <> compare arg arg'- compare (ExDispatch expr attr) (ExDispatch expr' attr') = compare expr expr' <> compare attr attr'- compare (ExMeta meta) (ExMeta meta') = compare meta meta'- compare (ExAny slot) (ExAny slot') = compare slot slot'- compare (ExPhiMeet prefix idx expr) (ExPhiMeet prefix' idx' expr') = compare prefix prefix' <> compare idx idx' <> compare expr expr'- compare (ExPhiAgain prefix idx expr) (ExPhiAgain prefix' idx' expr') = compare prefix prefix' <> compare idx idx' <> compare expr expr'- compare (ExBytes bts) (ExBytes bts') = compare bts bts'- compare left right = compare (rank left) (rank right)+ compare left right+ | identical left right = EQ+ | otherwise = ordered left right where+ ordered :: Expression -> Expression -> Ordering+ ordered (ExFormation bds) (ExFormation bds') = compare bds bds'+ ordered (ExApplication expr arg) (ExApplication expr' arg') = compare expr expr' <> compare arg arg'+ ordered (ExDispatch expr attr) (ExDispatch expr' attr') = compare expr expr' <> compare attr attr'+ ordered (ExMeta meta) (ExMeta meta') = compare meta meta'+ ordered (ExAny slot) (ExAny slot') = compare slot slot'+ ordered (ExPhiMeet prefix idx expr) (ExPhiMeet prefix' idx' expr') = compare prefix prefix' <> compare idx idx' <> compare expr expr'+ ordered (ExPhiAgain prefix idx expr) (ExPhiAgain prefix' idx' expr') = compare prefix prefix' <> compare idx idx' <> compare expr expr'+ ordered (ExBytes bts) (ExBytes bts') = compare bts bts'+ ordered one two = compare (rank one) (rank two) rank :: Expression -> Int rank = \case ExFormation _ -> 0@@ -244,10 +248,11 @@ hashExpression :: Expression -> Int hashExpression term = case known term of- Facts digest _ _ _ -> digest+ Facts digest _ _ _ _ -> digest hashShape :: Expression -> Int-hashShape = layer (const 0) hashShape+hashShape term = case known term of+ Facts _ shape _ _ _ -> shape isName :: Text -> Bool isName = T.isPrefixOf "n·"@@ -572,22 +577,38 @@ children _ = [] symbols :: Expression -> [Int]-symbols = goExpr+symbols whole = case goExpr (IntMap.empty, IntSet.empty, []) whole of+ (_, _, found) -> reverse found where- goExpr :: Expression -> [Int]- goExpr (ExFormation bds) = concatMap goBinding bds- goExpr (ExApplication expr arg) = goExpr expr ++ goArgument arg- goExpr (ExDispatch expr _) = goExpr expr- goExpr (ExPhiMeet _ _ expr) = goExpr expr- goExpr (ExPhiAgain _ _ expr) = goExpr expr- goExpr _ = []- goBinding :: Binding -> [Int]- goBinding (BiTau _ expr) = goExpr expr- goBinding (BiLambda (FnSymbol idx)) = [idx]- goBinding _ = []- goArgument :: Argument -> [Int]- goArgument (ArTau _ expr) = goExpr expr- goArgument (ArAlpha _ expr) = goExpr expr+ goExpr :: (IntMap.IntMap [Expression], IntSet.IntSet, [Int]) -> Expression -> (IntMap.IntMap [Expression], IntSet.IntSet, [Int])+ goExpr walked@(seen, met, found) term+ | compound term && term `elem` IntMap.findWithDefault [] digest seen = walked+ | compound term = nested (IntMap.insertWith (++) digest [term] seen, met, found) term+ | otherwise = nested walked term+ where+ digest :: Int+ digest = hashExpression term+ compound :: Expression -> Bool+ compound (ExFormation _) = True+ compound (ExApplication _ _) = True+ compound (ExDispatch _ _) = True+ compound _ = False+ nested :: (IntMap.IntMap [Expression], IntSet.IntSet, [Int]) -> Expression -> (IntMap.IntMap [Expression], IntSet.IntSet, [Int])+ nested walked (ExFormation bds) = List.foldl' goBinding walked bds+ nested walked (ExApplication expr arg) = goArgument (goExpr walked expr) arg+ nested walked (ExDispatch expr _) = goExpr walked expr+ nested walked (ExPhiMeet _ _ expr) = goExpr walked expr+ nested walked (ExPhiAgain _ _ expr) = goExpr walked expr+ nested walked _ = walked+ goBinding :: (IntMap.IntMap [Expression], IntSet.IntSet, [Int]) -> Binding -> (IntMap.IntMap [Expression], IntSet.IntSet, [Int])+ goBinding walked (BiTau _ expr) = goExpr walked expr+ goBinding walked@(seen, met, found) (BiLambda (FnSymbol idx))+ | IntSet.member idx met = walked+ | otherwise = (seen, IntSet.insert idx met, idx : found)+ goBinding walked _ = walked+ goArgument :: (IntMap.IntMap [Expression], IntSet.IntSet, [Int]) -> Argument -> (IntMap.IntMap [Expression], IntSet.IntSet, [Int])+ goArgument walked (ArTau _ expr) = goExpr walked expr+ goArgument walked (ArAlpha _ expr) = goExpr walked expr lifted :: Int -> Int -> Expression -> Expression lifted floor' offset = goExpr@@ -624,7 +645,7 @@ countNodes :: Expression -> Int countNodes term = case known term of- Facts _ size _ _ -> size+ Facts _ _ size _ _ -> size tally :: Expression -> Int tally (ExFormation bds) = 1 + sum (map nodesInBinding bds) + length bds@@ -643,11 +664,11 @@ inert :: Expression -> Bool inert term = case known term of- Facts _ _ still _ -> still+ Facts _ _ _ still _ -> still distinct :: Expression -> Bool distinct term = case known term of- Facts _ _ _ unique -> unique+ Facts _ _ _ _ unique -> unique unrepeated :: Expression -> Bool unrepeated (ExFormation bds) = isNothing (repeated bds)
src/CLI/Helpers.hs view
@@ -211,7 +211,7 @@ ctx._saveEval (EvHeader header aiming._locator target) heading ctx._saveEval printCtx judgment aiming._locator mapM_ (ctx._saveEval . resited ctx._site aiming._locator) . reverse =<< readIORef held- pure (universe, aiming{_site = aiming._locator, _saveEval = ctx._saveEval})+ pure (universe, aiming{_site = aiming._locator, _opened = Just (ctx._nesting, judgment, aiming._locator), _saveEval = ctx._saveEval}) aimed _ _ _ (Just _) expr _ = invalidCLIArguments (printf "The option --inside requires the input expression to be a formation, but given: %s" (P.printExpression expr))
src/Morph.hs view
@@ -79,7 +79,7 @@ data Kindred = Kindred Expression Expression Firing Answer -data Renaming = Renaming (IORef (Map.Map Int Int)) Spots (IORef (Set.Set Firing))+data Renaming = Renaming (IORef (Map.Map Int Int)) Spots (IORef (Set.Set Firing)) (IORef (Store Expression)) data Answer = Answer Expression Expression@@ -313,41 +313,45 @@ spotted :: Spots -> Expression -> Maybe Int spotted (Spots known _) term = lookup term (Map.findWithDefault [] (hashExpression term) known) +type Abstraction = (Expression, Map.Map Int Expression)+ abstracted :: Sides -> Spots -> Expression -> IO (Expression, [(Int, Expression)]) abstracted store spots form = do cache <- newIORef Map.empty- goExpr cache form+ second Map.toList <$> goExpr cache form where- goExpr :: IORef (Map.Map T.Text (Expression, [(Int, Expression)])) -> Expression -> IO (Expression, [(Int, Expression)])- goExpr cache term = maybe (nested cache term) (\idx -> pure (ExFormation [BiLambda (FnSymbol idx)], [(idx, term)])) (spotted spots term)- nested :: IORef (Map.Map T.Text (Expression, [(Int, Expression)])) -> Expression -> IO (Expression, [(Int, Expression)])+ goExpr :: IORef (Map.Map Int [(Expression, Abstraction)]) -> Expression -> IO Abstraction+ goExpr cache term = do+ done <- readIORef cache+ case lookup term (Map.findWithDefault [] (hashExpression term) done) of+ Just again -> pure again+ Nothing -> do+ made@(made', posed) <- maybe (nested cache term) (\idx -> pure (ExFormation [BiLambda (FnSymbol idx)], Map.singleton idx term)) (spotted spots term)+ _ <- evaluate made'+ _ <- evaluate posed+ made <$ modifyIORef' cache (Map.insertWith (++) (hashExpression term) [(term, made)])+ nested :: IORef (Map.Map Int [(Expression, Abstraction)]) -> Expression -> IO Abstraction nested cache term@(ExMeta name) | isName name = do- done <- readIORef cache- case Map.lookup name done of- Just again -> pure again- Nothing -> do- side <- opened store term- made <-- if side == term- then pure (term, [])- else do- (side', posed) <- goExpr cache side- if side' == side then pure (term, posed) else (,posed) <$> named store side'- made <$ modifyIORef' cache (Map.insert name made)+ side <- opened store term+ if side == term+ then pure (term, Map.empty)+ else do+ (side', posed) <- goExpr cache side+ if side' == side then pure (term, posed) else (,posed) <$> named store side' nested cache term@(ExFormation bds) = do parts <- mapM (goBinding cache) bds- pure (intact bds term ExFormation (map fst parts), concatMap snd parts)+ pure (intact bds term ExFormation (map fst parts), Map.unions (map snd parts)) nested cache term@(ExApplication expr arg) = do (expr', one) <- goExpr cache expr (arg', two) <- goArgument cache arg- pure (intact (expr, arg) term (uncurry ExApplication) (expr', arg'), one ++ two)+ pure (intact (expr, arg) term (uncurry ExApplication) (expr', arg'), Map.union one two) nested cache term@(ExDispatch expr attr) = first (intact expr term (`ExDispatch` attr)) <$> goExpr cache expr- nested _ term = pure (term, [])- goBinding :: IORef (Map.Map T.Text (Expression, [(Int, Expression)])) -> Binding -> IO (Binding, [(Int, Expression)])+ nested _ term = pure (term, Map.empty)+ goBinding :: IORef (Map.Map Int [(Expression, Abstraction)]) -> Binding -> IO (Binding, Map.Map Int Expression) goBinding cache bd@(BiTau attr expr) = first (intact expr bd (BiTau attr)) <$> goExpr cache expr- goBinding _ bd = pure (bd, [])- goArgument :: IORef (Map.Map T.Text (Expression, [(Int, Expression)])) -> Argument -> IO (Argument, [(Int, Expression)])+ goBinding _ bd = pure (bd, Map.empty)+ goArgument :: IORef (Map.Map Int [(Expression, Abstraction)]) -> Argument -> IO (Argument, Map.Map Int Expression) goArgument cache arg@(ArTau attr expr) = first (intact expr arg (ArTau attr)) <$> goExpr cache expr goArgument cache arg@(ArAlpha alpha expr) = first (intact expr arg (ArAlpha alpha)) <$> goExpr cache expr @@ -385,12 +389,13 @@ adopted ctx@ReduceContext{_memo = Just (Memo _ _ _ _ (Kin places _ _) _)} (Kindred key form firing answer, pairing, posed) target = do table <- newIORef pairing visiting <- newIORef Set.empty+ renamed <- newIORef Map.empty Spots known _ <- readIORef places- adopt ctx (Renaming table (Spots known (Map.fromList [(idx, fromMaybe (ExFormation [BiLambda (FnSymbol idx')]) (lookup idx' posed)) | idx <- symbols key, Just idx' <- [Map.lookup idx pairing]])) visiting) firing key form answer (Just target)+ adopt ctx (Renaming table (Spots known (Map.fromList [(idx, fromMaybe (ExFormation [BiLambda (FnSymbol idx')]) (lookup idx' posed)) | idx <- symbols key, Just idx' <- [Map.lookup idx pairing]])) visiting renamed) firing key form answer (Just target) adopted _ _ _ = throwIO (userError "A renamed answer needs the memo of --acyclic=plausible") adopt :: ReduceContext -> Renaming -> Firing -> Expression -> Expression -> Answer -> Maybe Expression -> IO Answer-adopt ctx renaming@(Renaming table _ visiting) firing key form answer target = do+adopt ctx renaming@(Renaming table _ visiting _) firing key form answer target = do modifyIORef' visiting (Set.insert firing) firing' <- refired ctx renaming firing existing <- remembered ctx._memo firing'@@ -440,40 +445,37 @@ operand bytes = pure bytes renamedTerm :: ReduceContext -> Renaming -> Expression -> IO Expression-renamedTerm ctx renaming@(Renaming _ spots@(Spots _ spelt) _) term = do- renamed <- newIORef Map.empty- goExpr renamed term+renamedTerm ctx renaming@(Renaming _ spots@(Spots _ spelt) _ renamed) = goExpr where- goExpr :: IORef (Map.Map T.Text Expression) -> Expression -> IO Expression- goExpr renamed expr = maybe (nested renamed expr) (spot renamed expr) (spotted spots expr)- spot :: IORef (Map.Map T.Text Expression) -> Expression -> Int -> IO Expression- spot renamed expr idx = maybe (nested renamed expr) pure (Map.lookup idx spelt)- nested :: IORef (Map.Map T.Text Expression) -> Expression -> IO Expression- nested renamed expr@(ExMeta name)+ goExpr :: Expression -> IO Expression+ goExpr expr = do+ done <- readIORef renamed+ case lookup expr (Map.findWithDefault [] (hashExpression expr) done) of+ Just again -> pure again+ Nothing -> do+ made <- evaluate =<< maybe (nested expr) (spot expr) (spotted spots expr)+ made <$ modifyIORef' renamed (Map.insertWith (++) (hashExpression expr) [(expr, made)])+ spot :: Expression -> Int -> IO Expression+ spot expr idx = maybe (nested expr) pure (Map.lookup idx spelt)+ nested :: Expression -> IO Expression+ nested expr@(ExMeta name) | isName name = do- done <- readIORef renamed- case Map.lookup name done of- Just again -> pure again- Nothing -> do- side <- opened ctx._sides expr- made <- if side == expr then pure expr else named ctx._sides =<< goExpr renamed side- made <$ modifyIORef' renamed (Map.insert name made)- nested renamed expr = walked renamed expr- walked :: IORef (Map.Map T.Text Expression) -> Expression -> IO Expression- walked renamed whole@(ExFormation bds) = intact bds whole ExFormation <$> suffixed (goBinding renamed) bds- walked renamed whole@(ExApplication expr arg) = intact (expr, arg) whole (uncurry ExApplication) <$> ((,) <$> goExpr renamed expr <*> goArgument renamed arg)- walked renamed whole@(ExDispatch expr attr) = intact expr whole (`ExDispatch` attr) <$> goExpr renamed expr- walked _ expr = pure expr- goBinding :: IORef (Map.Map T.Text Expression) -> Binding -> IO Binding- goBinding renamed bd@(BiTau attr expr) = intact expr bd (BiTau attr) <$> goExpr renamed expr- goBinding _ (BiLambda (FnSymbol idx)) = BiLambda . FnSymbol <$> renamedSymbol ctx renaming idx- goBinding _ bd = pure bd- goArgument :: IORef (Map.Map T.Text Expression) -> Argument -> IO Argument- goArgument renamed arg@(ArTau attr expr) = intact expr arg (ArTau attr) <$> goExpr renamed expr- goArgument renamed arg@(ArAlpha alpha expr) = intact expr arg (ArAlpha alpha) <$> goExpr renamed expr+ side <- opened ctx._sides expr+ if side == expr then pure expr else named ctx._sides =<< goExpr side+ nested whole@(ExFormation bds) = intact bds whole ExFormation <$> suffixed goBinding bds+ nested whole@(ExApplication expr arg) = intact (expr, arg) whole (uncurry ExApplication) <$> ((,) <$> goExpr expr <*> goArgument arg)+ nested whole@(ExDispatch expr attr) = intact expr whole (`ExDispatch` attr) <$> goExpr expr+ nested expr = pure expr+ goBinding :: Binding -> IO Binding+ goBinding bd@(BiTau attr expr) = intact expr bd (BiTau attr) <$> goExpr expr+ goBinding (BiLambda (FnSymbol idx)) = BiLambda . FnSymbol <$> renamedSymbol ctx renaming idx+ goBinding bd = pure bd+ goArgument :: Argument -> IO Argument+ goArgument arg@(ArTau attr expr) = intact expr arg (ArTau attr) <$> goExpr expr+ goArgument arg@(ArAlpha alpha expr) = intact expr arg (ArAlpha alpha) <$> goExpr expr renamedSymbol :: ReduceContext -> Renaming -> Int -> IO Int-renamedSymbol ctx renaming@(Renaming table _ visiting) idx = do+renamedSymbol ctx renaming@(Renaming table _ visiting _) idx = do known <- readIORef table maybe unknown pure (Map.lookup idx known) where
+ src/Pointer.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE MagicHash #-}+{-# OPTIONS_GHC -fno-hpc #-}++-- SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com+-- SPDX-License-Identifier: MIT++module Pointer (identical) where++import GHC.Exts (isTrue#, reallyUnsafePtrEquality#)++identical :: a -> a -> Bool+identical left right = left `seq` right `seq` isTrue# (reallyUnsafePtrEquality# left right)+{-# NOINLINE identical #-}
src/Replacer.hs view
@@ -97,7 +97,10 @@ | length (filter (== ptn) dropped) < sum (map (occurrences ptn) (children replaced)) = go (ptn : dropped) (ptns, repls) go _ pending = pending occurrences :: Expression -> Expression -> Int- occurrences ptn term = (if term == ptn then 1 else 0) + sum (map (occurrences ptn) (children term))+ occurrences ptn term+ | inert term && not (inert ptn) = 0+ | term == ptn = 1+ | otherwise = sum (map (occurrences ptn) (children term)) children :: Expression -> [Expression] children (ExFormation bds) = [inner | BiTau _ inner <- bds] children (ExDispatch inner _) = [inner]
src/Sides.hs view
@@ -49,27 +49,39 @@ spelled :: Sides -> Expression -> IO Expression spelled (Sides store) whole = do Store terms _ _ kept _ <- readIORef store- cache <- newIORef Map.empty- let goExpr :: Expression -> IO Expression- goExpr term@(ExMeta name)- | Set.member name kept = do- done <- readIORef cache- case Map.lookup name done of- Just again -> pure again- Nothing -> do- made <- maybe (pure term) goExpr (Map.lookup name terms)- made <$ modifyIORef' cache (Map.insert name made)- goExpr term@(ExFormation bds) = intact bds term ExFormation <$> mapM goBinding bds- goExpr term@(ExApplication inner arg) = intact (inner, arg) term (uncurry ExApplication) <$> ((,) <$> goExpr inner <*> goArgument arg)- goExpr term@(ExDispatch inner attr) = intact inner term (`ExDispatch` attr) <$> goExpr inner- goExpr term = pure term- goBinding :: Binding -> IO Binding- goBinding bd@(BiTau attr term) = intact term bd (BiTau attr) <$> goExpr term- goBinding bd = pure bd- goArgument :: Argument -> IO Argument- goArgument arg@(ArTau attr term) = intact term arg (ArTau attr) <$> goExpr term- goArgument arg@(ArAlpha alpha term) = intact term arg (ArAlpha alpha) <$> goExpr term- goExpr whole+ if Set.null kept+ then pure whole+ else do+ cache <- newIORef IntMap.empty+ goExpr terms kept cache whole+ where+ goExpr :: Map.Map Text Expression -> Set.Set Text -> IORef (IntMap.IntMap [(Expression, Maybe Expression)]) -> Expression -> IO Expression+ goExpr terms kept cache term = do+ done <- readIORef cache+ case lookup term (IntMap.findWithDefault [] digest done) of+ Just again -> pure (fromMaybe term again)+ Nothing -> do+ made <- nested term+ let change = if made == term then Nothing else Just made+ made <$ modifyIORef' cache (IntMap.insertWith (++) digest [(term, change)])+ where+ digest :: Int+ digest = hashExpression term+ walk :: Expression -> IO Expression+ walk = goExpr terms kept cache+ nested :: Expression -> IO Expression+ nested meta@(ExMeta name)+ | Set.member name kept = maybe (pure meta) walk (Map.lookup name terms)+ nested form@(ExFormation bds) = intact bds form ExFormation <$> mapM goBinding bds+ nested app@(ExApplication inner arg) = intact (inner, arg) app (uncurry ExApplication) <$> ((,) <$> walk inner <*> goArgument arg)+ nested disp@(ExDispatch inner attr) = intact inner disp (`ExDispatch` attr) <$> walk inner+ nested other = pure other+ goBinding :: Binding -> IO Binding+ goBinding bd@(BiTau attr expr) = intact expr bd (BiTau attr) <$> walk expr+ goBinding bd = pure bd+ goArgument :: Argument -> IO Argument+ goArgument arg@(ArTau attr expr) = intact expr arg (ArTau attr) <$> walk expr+ goArgument arg@(ArAlpha alpha expr) = intact expr arg (ArAlpha alpha) <$> walk expr opened :: Sides -> Expression -> IO Expression opened store term = do
src/Sodg.hs view
@@ -30,17 +30,15 @@ | Put Int Text Int | Delta Int Text | Lambda Int Text+ | Terminator Int deriving (Eq, Show) data SodgException- = Terminated Text- | Patterned Text Text+ = Patterned Text Text | Unbound Text deriving (Exception) instance Show SodgException where- show (Terminated place) =- T.unpack ("The attribute " <> place <> " is ⊥, which no SODG command makes") show (Patterned place what) = T.unpack ("The term at " <> place <> " holds " <> what <> ", which only a pattern of a rule may hold, not a program") show (Unbound place) =@@ -62,7 +60,7 @@ go (Just around) _ ExXi walk = Right (around, walk) go Nothing place ExXi _ = Left (Unbound place) go _ _ ExRoot walk = Right (0, walk)- go _ place ExTermination _ = Left (Terminated place)+ go _ _ ExTermination (next, done) = Right (next, (next + 1, Terminator next : done)) go around place (ExDispatch base attr) walk = do name <- attribute place attr (from, (next, done)) <- go around place base walk@@ -132,3 +130,4 @@ Put self attr kid -> ["P", vertex self, T.unpack attr, vertex kid] Delta self data' -> ["Δ", vertex self, T.unpack data'] Lambda self name -> ["λ", vertex self, T.unpack name]+ Terminator self -> ["T", vertex self]
+ test-resources/rewriter-packs/custom/applies-a-match-equal-to-one-swallowed-beside-an-inert-term.yaml view
@@ -0,0 +1,15 @@+# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com+# SPDX-License-Identifier: MIT+---+repeat: 1+input: |+ [[+ a -> [[ k -> [[ m -> [[ ]].go ]], s -> [[ q -> Q ]] ]].go,+ b -> [[ ]].go+ ]]+output: '[[ a -> Q.done, b -> Q.done ]]'+rules:+ custom:+ - name: go-done+ pattern: '[[ !B1 ]].go'+ result: 'Q.done'
+ test-resources/sodg-packs/bottom-alone.yaml view
@@ -0,0 +1,7 @@+# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com+# SPDX-License-Identifier: MIT+---+input: '⊥'+output: |+ F c0+ T c1
test-resources/sodg-packs/bottom-argument.yaml view
@@ -2,4 +2,9 @@ # SPDX-License-Identifier: MIT --- input: '⟦ a ↦ Φ.f( x ↦ ⊥ ) ⟧'-fails: 'The attribute Φ.a.x is ⊥'+output: |+ F c0 a+ D c1 c0 f+ T c2+ A c3 c1 x c2+ P c0 a c3
+ test-resources/sodg-packs/bottom-dispatch.yaml view
@@ -0,0 +1,13 @@+# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com+# SPDX-License-Identifier: MIT+---+input: '⟦ x ↦ ⊥.foo, y ↦ ⊥( α0 ↦ ⟦⟧ ) ⟧'+output: |+ F c0 x y+ T c1+ D c2 c1 foo+ P c0 x c2+ T c3+ F c4+ A c5 c3 α0 c4+ P c0 y c5
test-resources/sodg-packs/bottom.yaml view
@@ -2,4 +2,9 @@ # SPDX-License-Identifier: MIT --- input: '⟦ a ↦ ⟦ b ↦ ⊥ ⟧ ⟧'-fails: 'The attribute Φ.a.b is ⊥'+output: |+ F c0 a+ F c1 b+ T c2+ P c1 b c2+ P c0 a c1
test/ASTSpec.hs view
@@ -16,7 +16,7 @@ import GHC.Clock (getMonotonicTime) import Grown (Grown (..)) import System.Timeout (timeout)-import Test.Hspec (Spec, describe, it, shouldBe, shouldNotBe, shouldSatisfy)+import Test.Hspec (Spec, describe, it, shouldBe, shouldNotBe, shouldReturn, shouldSatisfy) import Test.Hspec.QuickCheck (prop) spec :: Spec@@ -204,6 +204,14 @@ let exprs = [ExDispatch ExRoot AtRho, ExApplication ExRoot (ArTau AtRho ExRoot), ExMeta "e", ExTermination, ExRoot, ExXi, ExFormation []] first : _ = sort exprs in first `shouldBe` ExFormation []+ describe "Expression Ord instance over a term holding the level below it twice" $+ it "compares the term with itself without walking it as a tree" $ do+ let doubled :: Expression -> Expression+ doubled inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel "qa") inner]+ deep :: Expression+ deep = iterate doubled (ExFormation [BiLambda (FnSymbol 3)]) !! 60+ timeout 10000000 (evaluate (compare (ExApplication deep (ArTau (AtLabel "ve") deep)) (ExApplication deep (ArTau (AtLabel "ve") deep))))+ `shouldReturn` Just EQ describe "countNodes counts ExFormation with non-tau bindings" $ forM_@@ -427,6 +435,11 @@ `shouldBe` hashShape (ExFormation [BiTau (AtLabel "n") (ExFormation [BiLambda (FnSymbol 5)])]) it "does not hash two terms differing by a datum alike" $ hashShape (ExFormation [BiDelta (BtOne "0A")]) `shouldNotBe` hashShape (ExFormation [BiDelta (BtOne "0B")])+ it "hashes a term holding the level below it twice without walking it as a tree" $ do+ let doubled :: Expression -> Expression+ doubled inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel "x") inner]+ deep = iterate doubled (ExFormation [BiLambda (FnSymbol 1)]) !! 60+ hashShape deep `shouldBe` hashShape (doubled (iterate doubled (ExFormation [BiLambda (FnSymbol 2)]) !! 59)) describe "BaseObject pattern" $ do it "constructs a Q-dispatch expression" $@@ -598,6 +611,18 @@ it "tells apart two formations that differ deep inside" $ ExFormation [BiTau (AtLabel "lu") (ExDispatch ExXi (AtLabel "op"))] `shouldNotBe` ExFormation [BiTau (AtLabel "lu") (ExDispatch ExXi (AtLabel "po"))]++ describe "symbols" $ do+ it "names every symbol once, in the order it first stands" $+ symbols (ExFormation [BiTau (AtLabel "mo") (ExFormation [BiLambda (FnSymbol 8)]), BiTau (AtLabel "ar") (ExFormation [BiLambda (FnSymbol 2)]), BiTau (AtLabel "si") (ExFormation [BiLambda (FnSymbol 8)])])+ `shouldBe` [8, 2]+ it "walks every distinct term once in a term holding the level below it twice" $ do+ let doubled :: Expression -> Expression+ doubled inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel "ku") (ExApplication (ExDispatch inner (AtLabel "te")) (ArTau (AtLabel "of") inner))]+ deep :: Expression+ deep = iterate doubled (ExFormation [BiLambda (FnSymbol 5), BiTau (AtLabel "ny") (ExFormation [BiLambda (FnSymbol 4)])]) !! 60+ timeout 10000000 (let found = symbols deep in found <$ evaluate (length found))+ `shouldReturn` Just [5, 4] describe "Expression Show instance" $ it "does not show what a node carries besides its parts" $
test/CLISpec.hs view
@@ -1742,6 +1742,36 @@ records <- map (dropWhile (== ' ')) . lines <$> readProtocol path records `shouldContain` ["looped 𝜎5 := 𝑛·5·1.plus # plausible, repeats 𝑛·0·4"] + describe "over a world whose levels share the value below them twice" $ do+ let level :: String -> String+ level inner = "⟦ ρ ↦ ∅, x ↦ ∅, l ↦ ⟦ ρ ↦ ∅, x ↦ ∅, y ↦ ∅, m ↦ ⟦ ρ ↦ ∅, f ↦ ⟦ λ ⤍ L_f, ρ ↦ ∅ ⟧ ⟧ ⟧( x ↦ ξ.x, y ↦ ξ.x ).m ⟧( x ↦ " ++ inner ++ " ).l"+ world = "⟦ mk ↦ " ++ iterate level "⟦ ρ ↦ ∅ ⟧" !! 24 ++ ", app ↦ Φ.mk.f ⟧"+ atoms = T.pack "- λ: L_f\n 𝑛: ⟦ λ ⤍ 𝜎 ⟧\n"+ triple :: String -> String+ triple target = "⟦ dataized(target, big) ↦ L_dataized:λ, peek(target) ↦ L_peek:λ, p ↦ ⟦ a ↦ Φ.dataized( target ↦ Φ.u, big ↦ Φ.mk.f ), b ↦ Φ.peek( target ↦ Φ.v ), c ↦ Φ.dataized( target ↦ Φ." ++ target ++ ", big ↦ Φ.mk.f ), λ ⤍ L_triple ⟧.φ, u ↦ ⟦ λ ⤍ 𝜎1 ⟧, v ↦ ⟦ λ ⤍ 𝜎2 ⟧, w ↦ ⟦ λ ⤍ 𝜎1 ⟧, mk ↦ " ++ iterate level "⟦ ρ ↦ ∅ ⟧" !! 30 ++ " ⟧"+ firings = T.pack "- λ: L_dataized\n dataize: {𝛿1: $.target}\n morph: {𝑛1: $.big}\n 𝑛: ⟦ λ ⤍ 𝜎 ⟧\n- λ: L_peek\n dataize: {𝛿1: $.target}\n 𝑛: ⟦ λ ⤍ 𝜎 ⟧\n- λ: L_triple\n morph: {𝑛1: $.a, 𝑛2: $.b, 𝑛3: $.c}\n evaluate: {𝑛4: 𝑛1, 𝑛5: 𝑛2, 𝑛6: 𝑛3}\n 𝑛: ⟦ φ ↦ ⟦ a ↦ 𝑛4, b ↦ 𝑛5, c ↦ 𝑛6 ⟧ ⟧\n"+ recorded :: String -> IO (Maybe [String])+ recorded target =+ timeout 60000000 $+ withTempFile "protocolXXXXXX.txt" $ \(path, stream) -> do+ hClose stream+ withLambdasOf firings $ \file ->+ withStdin (triple target) $+ testCLISucceeded ["dataize", "--symbolic=" ++ file, "--locator=Q.p", "--acyclic=plausible", "--max-loops=1", "--partial", "--cheat", "--sweet", "--hide-rho", "--max-cycles=1000", "--minutes=" ++ path] ["⊥"]+ map (dropWhile (== ' ')) . lines <$> readProtocol path+ it "fires the atom without walking the shared values as a tree" $+ timeout+ 60000000+ ( withLambdasOf atoms $ \file ->+ withStdin world $+ testCLISucceeded ["dataize", "--symbolic=" ++ file, "--locator=Q.app", "--acyclic=plausible", "--max-loops=1", "--max-cycles=1000"] ["40-45-00-00-00-00-00-00"]+ )+ >>= (`shouldBe` Just ())+ it "takes the answer of a kindred firing without walking the shared values as a tree" $+ recorded "v" >>= (`shouldSatisfy` maybe False (elem "renamed 𝑛·1·14 ⇛ 𝜎5:λ # from 𝑛·1·5, 𝜎1 as 𝜎2, 𝜎3 as 𝜎5"))+ it "takes the answer of a firing of the same operands without walking the shared values as a tree" $+ recorded "w" >>= (`shouldSatisfy` maybe False (elem "recalled 𝑛·1·5 ⇒ 𝜎3:λ"))+ describe "over a recursion that hands its own growing call to an atom" $ do let world = "⟦ go(x) ↦ ⟦ λ ⤍ L_go ⟧, seq(i) ↦ ⟦ ok ↦ Φ.go( Φ.seq( i.next ).ok ) ⟧, app ↦ Φ.seq( 𝜎1:λ ).ok ⟧" atoms = T.pack "- λ: L_go\n morph: {𝑛1: $.x}\n 𝑛: 𝑛1\n"@@ -3896,6 +3926,39 @@ records <- readProtocol path take 2 (lines records) `shouldBe` ["𝔻(Φ.a🌵0):", " 𝑛·0·1 := ∅:x( x ↦ 2A-:Δ )"] + it "opens a single morph block in the text protocol it aims inside" $+ withTempFile "protocolXXXXXX.txt" $ \(path, stream) -> do+ hClose stream+ withStdin "⟦ app ↦ ⟦ x ↦ ∅, φ ↦ ξ.x ⟧ ⟧" $+ testCLISucceeded ["morph", "--inside=Φ.app( x ↦ ⟦ Δ ⤍ 02- ⟧ )", "--minutes=" ++ path, "--sweet", "--hide-rho", "--quiet"] []+ records <- readProtocol path+ length (filter ("𝕄(Φ.a🌵0):" `isInfixOf`) (lines records)) `shouldBe` 1+ take 2 (drop 1 (lines records)) `shouldBe` [" remembered 𝑛·0·1 ≡ Φ.app # ⟦ x ↦ ∅, φ ↦ x ⟧", " 𝑛·0·2 := Φ.app( x ↦ 02-:Δ )"]++ it "opens a single dataize element in the XML protocol it aims inside" $+ withTempFile "protocolXXXXXX.xml" $ \(path, stream) -> do+ hClose stream+ withStdin "⟦ app ↦ ⟦ x ↦ ∅, φ ↦ ξ.x ⟧ ⟧" $+ testCLISucceeded ["dataize", "--inside=⟦ Δ ⤍ 02- ⟧", "--protocol=" ++ path, "--sweet", "--hide-rho", "--quiet"] []+ records <- readProtocol path+ length (filter (isInfixOf "<dataize at=\"Φ.a🌵0\">") (lines records)) `shouldBe` 1++ it "keeps opening the block of a judgment nested in the universe it aims inside" $+ withTempFile "protocolXXXXXX.txt" $ \(path, stream) -> do+ hClose stream+ withStdin universe $+ testCLISucceeded ["dataize", symbolic, "--inside=5.plus( 6 )", "--minutes=" ++ path, "--sweet", "--hide-rho", "--quiet"] []+ records <- readProtocol path+ take 3 (lines records) `shouldBe` ["𝔻(Φ.a🌵0):", " 𝕄(Φ.a🌵0):", " normalized 𝑛·0·1 := ⟦ φ ↦ ∅, plus(x) ↦ L_number_plus:λ ⟧ # Φ.number"]++ it "opens a single morph element in the XML protocol it aims inside" $+ withTempFile "protocolXXXXXX.xml" $ \(path, stream) -> do+ hClose stream+ withStdin "⟦ app ↦ ⟦ x ↦ ∅, φ ↦ ξ.x ⟧ ⟧" $+ testCLISucceeded ["morph", "--inside=Φ.app( x ↦ ⟦ Δ ⤍ 02- ⟧ )", "--protocol=" ++ path, "--sweet", "--hide-rho", "--quiet"] []+ records <- readProtocol path+ length (filter (isInfixOf "<morph at=\"Φ.a🌵0\">") (lines records)) `shouldBe` 1+ it "cannot be used together with --locator" $ withStdin universe $ testCLIFailed ["dataize", "--inside=Q.@", "--locator=Q.@"] ["--inside and --locator cannot be used together"]@@ -4767,9 +4830,9 @@ withStdin "<object><o name=\"app\"><o name=\"x\" base=\"Φ.number\"/></o></object>" $ testCLISucceeded ["sodg", "--input=xmir"] ["F c0 app\nF c1 x\nD c2 c0 number\nP c1 x c2\nP c0 app c1\n"] - it "fails on ⊥ and names the attribute" $+ it "prints ⊥ as a terminator" $ withStdin "⟦ a ↦ ⊥ ⟧" $- testCLIFailed ["sodg"] ["The attribute Φ.a is ⊥"]+ testCLISucceeded ["sodg"] ["F c0 a\nT c1\nP c0 a c1\n"] it "rejects an option of other commands" $ withStdin "⟦⟧" $
test/MorphSpec.hs view
@@ -11,7 +11,7 @@ module MorphSpec (spec) where import AST-import Control.Exception (SomeException)+import Control.Exception (SomeException, evaluate) import Control.Monad import Data.Aeson (FromJSON) import Data.IORef (modifyIORef', newIORef, readIORef)@@ -30,7 +30,7 @@ import Inference (Conclusion (Answered), Premises (Concludes, Morphs), direct) import Lambdas (Lambdas, emptyLambdas) import Matcher (substEmpty)-import Morph (Deadline (..), ReduceContext (..), declared, emptyState, enter, execBuildTerm, factual, fired, inferred, insideUniverse, morph, morph', normalized, noted, voided)+import Morph (Answer (..), Deadline (..), Firing (..), ReduceContext (..), adopted, declared, emptyState, ended, enter, execBuildTerm, factual, fired, inferred, insideUniverse, kindle, kindred, memoized, morph, morph', normalized, noted, placed, voided) import Parser (Form (MONOFORM), parseExpressionThrows, parseExpressionThrows') import Rewriter (Rewritten) import Rule (RuleContext (RuleContext), matchExpressionWithRule')@@ -311,6 +311,41 @@ ctx <- enter (formation ExRoot 1300) base{_acyclic = Just Plausible, _deadline = Just (Deadline 31 due)} timeout 10000000 (enter (formation ExXi 1700) ctx) `shouldThrow` (\e -> "--max-seconds=31" `isInfixOf` show (e :: SomeException))++ describe "looks for a kindred firing in a term holding the level below it twice" $+ it "walks every distinct term once" $ do+ let doubled :: T.Text -> Expression -> Expression+ doubled label inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel label) inner]+ leaf = ExFormation [BiDelta (BtOne "01")]+ deep :: T.Text -> Expression+ deep label = iterate (doubled label) leaf !! 60+ memo <- memoized (Just Plausible)+ ctx <- defaultReduceContext ExRoot+ placed memo leaf 1+ found <- timeout 10000000 $ do+ kindle ctx._sides memo (deep "x") (Firing "L_f" [] []) (Joined (ExFormation [BiLambda (FnSymbol 2)]))+ kin <- kindred ctx{_memo = memo} (deep "y")+ pure (maybe [] (\(_, _, posed) -> posed) kin)+ found `shouldBe` Just []++ describe "takes the answer of a kindred firing holding the level below it twice" $+ it "renames every distinct term once" $ do+ let doubled :: Expression -> Expression+ doubled inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel "zo") inner]+ deep :: Int -> Expression+ deep idx = iterate doubled (ExFormation [BiLambda (FnSymbol idx)]) !! 60+ form :: Int -> Expression+ form idx = ExFormation [BiTau (AtLabel "on") (ExFormation [BiLambda (FnSymbol idx)]), BiLambda (Function "L_f")]+ kept :: Expression+ kept = deep 1+ memo <- memoized (Just Plausible)+ ctx <- defaultReduceContext ExRoot+ renamed <- timeout 10000000 $ do+ kindle ctx._sides memo (form 1) (Firing "L_f" [Left 1] [kept]) (Joined kept)+ kin <- kindred ctx{_memo = memo} (form 2)+ answer <- maybe (pure Raised) (\found -> adopted ctx{_memo = memo} found (form 2)) kin+ evaluate (hashExpression (ended answer))+ renamed `shouldBe` Just (hashExpression (deep 2)) describe "names a cut by the facts however wide they are" $ it "names a cut held at the end of a wide fact long before the deadline" $ do
test/ReplacerSpec.hs view
@@ -6,8 +6,11 @@ module ReplacerSpec where import AST+import Control.Exception (evaluate) import Control.Monad (forM_)+import Data.Text qualified as T import Replacer+import System.Timeout (timeout) import Test.Hspec (Example (Arg), Expectation, Spec, SpecWith, describe, it, shouldBe) test :: ReplaceExpressionFunc -> [(String, Expression, [Expression], [Expression], Expression)] -> SpecWith (Arg Expectation)@@ -353,3 +356,12 @@ , ExFormation [BiTau (AtLabel "vt") (ExDispatch ExXi (AtLabel "ek")), BiTau (AtLabel "te") ExRoot] ) ]++ describe "replace expression around a shared inert term" $+ it "does not walk an inert term for the sites a replaced site may hold" $ do+ let shared = iterate (\inner -> ExFormation [BiTau (AtLabel "l") inner, BiTau (AtLabel "r") inner]) ExRoot !! 20+ nested = ExDispatch (ExFormation []) (AtLabel "go")+ site = ExDispatch (ExFormation (BiTau (AtLabel "h") shared : [BiTau (AtLabel (T.pack ("n" ++ show idx))) nested | idx <- [1 .. 1000 :: Int]])) (AtLabel "go")+ expr = ExFormation [BiTau (AtLabel "a") site, BiTau (AtLabel "b") nested]+ replaced <- timeout 5000000 (evaluate (replaceExpression (expr, site : replicate 1001 nested, map const (ExRoot : replicate 1001 ExXi)) == ExFormation [BiTau (AtLabel "a") ExRoot, BiTau (AtLabel "b") ExXi]))+ replaced `shouldBe` Just True
test/SidesSpec.hs view
@@ -7,11 +7,12 @@ import AST import Control.Monad (foldM)-import Sides (gauge, named, resolver, sides)+import Sides (gauge, minted, named, resolver, sides, spelled)+import System.Timeout (timeout) import Test.Hspec (Spec, describe, it, shouldBe) spec :: Spec-spec =+spec = do describe "gauge" $ do it "keeps the depth of every name it hands out" $ do store <- sides@@ -26,3 +27,15 @@ depth <- gauge store look <- resolver store deepness look depth outer `shouldBe` deepness (const Nothing) (const Nothing) (ExDispatch (ExApplication (ExDispatch ExRoot (AtLabel "g")) (ArTau (AtLabel "x") ExXi)) (AtLabel "q"))+ describe "spelled" $+ it "walks every distinct term once in a term holding the level below it twice" $ do+ let doubled :: Expression -> Expression+ doubled inner = ExFormation [BiTau AtRho inner, BiTau (AtLabel "x") inner]+ deep :: Expression -> Expression+ deep leaf = iterate doubled leaf !! 60+ arg :: Expression+ arg = ExApplication (ExDispatch ExRoot (AtLabel "f")) (ArTau (AtLabel "a") (ExDispatch ExRoot (AtLabel "g")))+ store <- sides+ (name, _) <- minted store arg+ found <- timeout 10000000 (hashExpression <$> spelled store (deep name))+ found `shouldBe` Just (hashExpression (deep arg))
test/SodgSpec.hs view
@@ -54,7 +54,7 @@ ) describe "sodg keeps its four promises on any program" $ do- prop "every F, D and A makes a fresh name and a command uses only names made above it" $ \(Grown grown) ->+ prop "every F, D, A and T makes a fresh name and a command uses only names made above it" $ \(Grown grown) -> let expr = scrubbed False grown in either (counterexample "the walk failed" . const False) (ordered expr) (commands expr) prop "every attached attribute of every formation gets exactly one P" $ \(Grown grown) ->@@ -80,6 +80,7 @@ Formation self _ -> [self] Dispatch self _ _ -> [self] Application self _ _ _ -> [self]+ Terminator self -> [self] _ -> [] used :: Command -> [Int] used = \case@@ -89,6 +90,7 @@ Put self _ kid -> [self, kid] Delta self _ -> [self] Lambda self _ -> [self]+ Terminator _ -> [] attached :: Expression -> [Command] -> Property attached expr graph =@@ -129,6 +131,7 @@ ExApplication inner (ArTau attr arg) -> ExApplication (scrubbed inside inner) (ArTau (label attr) (scrubbed inside arg)) ExApplication inner (ArAlpha alpha arg) -> ExApplication (scrubbed inside inner) (ArAlpha (indexed alpha) (scrubbed inside arg)) ExXi | inside -> ExXi+ ExTermination -> ExTermination _ -> ExRoot where binding :: Binding -> Maybe Binding