@@ -145,7 +145,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
145145 | otherwise = ([], [])
146146 farg = \x -> (x, Just $ CppAny [CppConst, CppRef])
147147 fieldLambdas flds
148− | (f' : fs') <- flds = [CppReturn $ CppLambda [CppCaptureAll] (farg <$> [f'])
148+ | (f' : fs') <- flds = [CppReturn . maybeRemCaps $
149+ CppLambda [CppCaptureAll] (farg <$> [f'])
149150 (Just $ CppAny [])
150151 (CppBlock $ fieldLambdas fs')]
151152 | otherwise = [CppReturn (CppObjectLiteral ((ctorKey, CppStringLiteral name) : zip fields' (CppVar <$> fields')))]
@@ -155,17 +156,17 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
155156 return $ CppVariableIntroduction (identToCpp ident, Just $ CppAny [CppConst]) [] (Just val')
156157
157158 -------------------------------------------------------------------------------------------------
158− toLambda :: [CppCaptureType] -> Cpp -> Cpp
159+ fnToLambda :: Cpp -> Cpp
159160 -------------------------------------------------------------------------------------------------
160− toLambda cs (CppFunction name args _ qs body) =
161+ fnToLambda (CppFunction name args _ qs body) =
161162 CppVariableIntroduction (name, Just $ CppAny [CppConst])
162163 (filter (==CppStatic) qs)
163− (Just (CppLambda cs' args (Just $ CppAny []) body))
164+ (Just (CppLambda cs args (Just $ CppAny []) body))
164165 where
165− cs' | (not . null) (qs `intersect` [CppInline, CppStatic]) = []
166− | otherwise = cs
167− toLambda cs (CppComment com cpp) = CppComment com (toLambda cs cpp)
168− toLambda _ _ = error "Not a function!"
166+ cs | (not . null) (qs `intersect` [CppInline, CppStatic]) = []
167+ | otherwise = [CppCaptureAll]
168+ fnToLambda (CppComment com cpp) = CppComment com (fnToLambda cpp)
169+ fnToLambda _ = error "Not a function!"
169170
170171 -------------------------------------------------------------------------------------------------
171172 asReturnBlock :: Cpp -> Cpp
@@ -178,8 +179,8 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
178179 convertNestedLambdas = everywhereOnCpp go
179180 where
180181 go :: Cpp -> Cpp
181− go f@(CppFunction {}) = toLambda [CppCaptureAll] f
182− go (CppLambda [] args rtyp body) = CppLambda [CppCaptureAll] args rtyp body
182+ go f@(CppFunction {}) = maybeRemCaps $ fnToLambda f
183+ go (CppLambda _ args rtyp body) = maybeRemCaps $ CppLambda [CppCaptureAll] args rtyp body
183184 go cpp = cpp
184185
185186 -------------------------------------------------------------------------------------------------
@@ -211,11 +212,12 @@ moduleToCpp env (Module _ mn imps _ foreigns decls) = do
211212
212213 toelem :: Cpp -> (String, Cpp)
213214 toelem (CppFunction name args rtyp _ (CppBlock body)) =
214− (name, withdict $ CppLambda [CppCaptureAll] args rtyp (CppBlock $ (accessor localdict <$> fns) ++ body))
215+ (name, withdict . maybeRemCaps $ CppLambda [CppCaptureAll]
216+ args rtyp (CppBlock $ (accessor localdict <$> fns) ++ body))
215217 toelem _ = error "not a function"
216218
217219 withdict :: Cpp -> Cpp
218− withdict cpp' =
220+ withdict cpp' = maybeRemCaps $
219221 CppLambda [CppCaptureAll] [(localdict, Just $ CppAny [CppConst, CppRef])]
220222 (Just $ CppAny [])
221223 (CppBlock [CppReturn cpp'])