From e069718174d5d7856c2d02303872fbe164638713 Mon Sep 17 00:00:00 2001 From: Maximilian Algehed Date: Sun, 16 Nov 2025 19:53:19 +0100 Subject: [PATCH 1/2] simplify runTermE --- src/Constrained/AbstractSyntax.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Constrained/AbstractSyntax.hs b/src/Constrained/AbstractSyntax.hs index 4efe15c..fbad9e2 100644 --- a/src/Constrained/AbstractSyntax.hs +++ b/src/Constrained/AbstractSyntax.hs @@ -104,6 +104,8 @@ runTermE env = \case V v -> case Env.lookup env v of Just a -> Right a Nothing -> Left (pure ("Couldn't find " ++ show v ++ " in " ++ show env)) + App f (ta :> Nil) -> semantics f <$> runTermE env ta + App f (ta :> tb :> Nil) -> semantics f <$> runTermE env ta <*> runTermE env tb App f ts -> do vs <- mapMList (fmap Identity . runTermE env) ts pure $ uncurryList_ runIdentity (semantics f) vs From 1f4f7ea83c02afdddbb1282efe2bb3690e325bfd Mon Sep 17 00:00:00 2001 From: Maximilian Algehed Date: Sun, 16 Nov 2025 20:00:15 +0100 Subject: [PATCH 2/2] explain what we're doing --- src/Constrained/AbstractSyntax.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Constrained/AbstractSyntax.hs b/src/Constrained/AbstractSyntax.hs index fbad9e2..354c504 100644 --- a/src/Constrained/AbstractSyntax.hs +++ b/src/Constrained/AbstractSyntax.hs @@ -104,6 +104,8 @@ runTermE env = \case V v -> case Env.lookup env v of Just a -> Right a Nothing -> Left (pure ("Couldn't find " ++ show v ++ " in " ++ show env)) + -- The first two cases here are an optimization to avoid dispatching to `mapMList` (which does all sorts of + -- unpacking and packing and doesn't fuse nicely with `uncurryList_`) App f (ta :> Nil) -> semantics f <$> runTermE env ta App f (ta :> tb :> Nil) -> semantics f <$> runTermE env ta <*> runTermE env tb App f ts -> do