@@ -497,9 +497,18 @@ buildDepMap ci used externs ctx startNames
497 Nothing -> error $ "Erasure/getArity: definition not found for " ++ show n
497 Nothing -> error $ "Erasure/getArity: definition not found for " ++ show n
499 -- convert applications of lambdas to lets
499 -- convert applications of lambdas to lets
500− -- Note that this transformation preserves de bruijn numbering
500+ -- note that this transformation preserves de bruijn numbering
501 lamToLet :: Term -> Term
501 lamToLet :: Term -> Term
502+ lamToLet tm = lamToLet' args f
504+ (f, args) = unApply tm
506+ lamToLet' :: [Term] -> Term -> Term
502− lamToLet (App _ (Bind n (Lam ty) tm) val) = Bind n (Let ty val) tm
507+ lamToLet' (v:vs) (Bind n (Lam ty) tm) = Bind n (Let ty v) $ lamToLet' vs tm
508+ lamToLet' [] tm = tm
509+ lamToLet' vs tm = error $
510+ "Erasure.hs:lamToLet': unexpected input: "
511+ ++ "vs = " ++ show vs ++ ", tm = " ++ show tm
504 -- split "\x_i -> T(x_i)" into [x_i] and T
513 -- split "\x_i -> T(x_i)" into [x_i] and T
505 unfoldLams :: Term -> ([Name], Term)
514 unfoldLams :: Term -> ([Name], Term)