Skip to content

Commit d203746

Browse files
Simplify runTermE (runtime-wise) (#63)
* simplify runTermE * explain what we're doing
1 parent 3730642 commit d203746

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Constrained/AbstractSyntax.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ runTermE env = \case
104104
V v -> case Env.lookup env v of
105105
Just a -> Right a
106106
Nothing -> Left (pure ("Couldn't find " ++ show v ++ " in " ++ show env))
107+
-- The first two cases here are an optimization to avoid dispatching to `mapMList` (which does all sorts of
108+
-- unpacking and packing and doesn't fuse nicely with `uncurryList_`)
109+
App f (ta :> Nil) -> semantics f <$> runTermE env ta
110+
App f (ta :> tb :> Nil) -> semantics f <$> runTermE env ta <*> runTermE env tb
107111
App f ts -> do
108112
vs <- mapMList (fmap Identity . runTermE env) ts
109113
pure $ uncurryList_ runIdentity (semantics f) vs

0 commit comments

Comments
 (0)